Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 WP_Query loops for custom post types on the same page
    text
    copied!<p>I'm having hard time with this problems since I cant figure it out. I'm using 2 WP_Query loops for custom post types (slider and portfolio) on the same page. I also created a custom meta box for both custom post types.</p> <p>So here is the code for index.php which Im using as Home template for displaying slider and portfolio items:</p> <pre><code>&lt;?php /* Template Name: Home */ ?&gt; &lt;?php get_header(); ?&gt; &lt;div id="header-container"&gt; &lt;div id="header"&gt; &lt;?php rm_slider(); ?&gt; // This is where Im calling slider function to display the slider. &lt;/div&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'portfolio', 'posts_per_page' =&gt; -1 )); ?&gt; &lt;?php if ($loop-&gt;have_posts()) { ?&gt; &lt;ul class="services"&gt; &lt;?php while ($loop-&gt;have_posts()) : $loop-&gt;the_post(); ?&gt; &lt;li&gt; &lt;?php if (has_post_thumbnail()) : the_post_thumbnail(); ?&gt; &lt;?php else: ?&gt; &lt;p&gt;No portfolio image&lt;/p&gt; &lt;?php endif; ?&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Client: &lt;?php echo get_post_meta($post-&gt;ID, '_project_client', true); ?&gt;&lt;/p&gt; &lt;p&gt;Client website: &lt;?php echo get_post_meta($post-&gt;ID, '_project_client_url', true); ?&gt;&lt;/p&gt; &lt;/li&gt; &lt;?php endwhile; } ?&gt; &lt;?php wp_reset_query(); ?&gt; &lt;?php get_footer(); ?&gt; </code></pre> <p>And here is the code for slider.php:</p> <pre><code>&lt;?php // create slider markup function rm_slider() { $slider_loop = new WP_Query( array( 'post_type' =&gt; 'slider', 'posts_per_page' =&gt; -1 )); if ($slider_loop-&gt;have_posts()) { ?&gt; &lt;div id="slider"&gt; &lt;div class="slider-container"&gt; &lt;?php while ($slider_loop-&gt;have_posts()) : $slider_loop-&gt;the_post(); ?&gt; &lt;div&gt; &lt;?php if (has_post_thumbnail()) : the_post_thumbnail(); ?&gt; &lt;?php else: ?&gt; &lt;p&gt;No slider image&lt;/p&gt; &lt;?php endif; ?&gt; &lt;div class="slide-info"&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php $slide_url = get_post_meta($post-&gt;ID, '_slide_url', true); if ($slide_url != '') { ?&gt; &lt;a href="&lt;?php echo $slide_url; ?&gt;" class="more-info"&gt;&lt;?php echo $slide_url; ?&gt;&lt;/a&gt; &lt;?php } else { echo 'empty?'; ?&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt;&lt;!-- .slider-container --&gt; &lt;/div&gt;&lt;!-- #slider --&gt; &lt;?php } wp_reset_query(); } ?&gt; </code></pre> <p>Im sure that the actual content from custom meta boxes is there, because when I only use 1 loop, it displays perfectly. But when using both loops, it only displays custom post meta only for the portfolio section. Im struggling with this problem whole day, please help me! Thanks :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload