• I have programmed a loop in a custom page template that pulls the single latest post from 4 different categories on the site, in 4 separate divs. Works great for 3 of the categories, but when I plug in the category ID of the 4th, posts from another category will appear instead. There are posts published in the faulty category that I’m trying to pull. I created a new test category and placed a post there, but the same thing happens.

    Here’s my code:

    <div class="item">
    <?php
        $args=array(
          'cat' => 14,
          'showposts' => 1,
          'caller_get_posts' => 1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php if(has_post_thumbnail()): ?>
    									<div class="visual-grid"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('grid_thumb'); ?></a>
    <div class="category-name">
    <?php
    $category = get_the_category();
    ?>
    <?php echo $category[0]->cat_name; ?>
    </div>
    </div>

    Any insight on what the problem could be?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m not 100% sure this is the answer, but it looks like 'caller_get_posts' parameter has been replaced by 'ignore_sticky_posts': https://codex.www.ads-software.com/Class_Reference/WP_Query#Sticky_Post_Parameters

    What happens when you switch 'caller_get_posts' with 'ignore_sticky_posts'?

    Actually, 'showposts' might be deprecated, too. Try replacing with 'posts_per_page'.

    Thread Starter katemgilbert

    (@katemgilbert)

    Thanks for the suggestion, Ken, but unfortunately it doesn’t have any effect. I also tried removing that argument altogether and leaving just the cat and showpost args, but to no avail.

    Thread Starter katemgilbert

    (@katemgilbert)

    Ken, my prior reply was before seeing your posts_per_page suggestion, but I switched that too, didn’t fix the issue, unfortunately.

    Hmm. Do you have a live link to the site?

    Thread Starter katemgilbert

    (@katemgilbert)

    Here it is:

    https://stilettodash.com/new-homepage-test/

    It’s the 2nd box that’s not pulling correctly. Right now I’m pulling a category that the post is cross-categorized with, and have hard-coded the category name in the black box.

    Here’s a snippet for a similar query I’ve used to pull the latest post from a category. Something you might need to do is make sure to “close the loop” by adding wp_reset_query(); at the end of each query.

    <?php
    	global $wp_query, $post;
    	$args = array(
    		'cat' => $your_category,
    		'posts_per_page' => 1,
    	);
    	$new_WP_Query = new WP_Query( $args );
    	while ( $new_WP_Query->have_posts() ) : $new_WP_Query->the_post();
    ?>
    
    	<!-- Put your thumbnail content here -->
    
    <?php
    	endwhile;
    	wp_reset_query();
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Some category IDs don't pull posts, others do’ is closed to new replies.