• Hello,
    My client (for whom I’ve built a theme) has installed this plugin and has noted that one of the loops on the homepage isn’t respecting the new “archive” status — the loop is showing a post which is marked as “archived”.

    Is there anything I need to do in particular to make this work with your plugin? I have set up the query so that it uses the default for post_status, and I would expect this to play nicely with the plugin.

    Here’s the relevant code, but basically it’s just a call to new WP_Query([ 'posts_per_page' => 6, 'category_in' => '3,4']);

    
    $args = array();
    
    $args['posts_per_page'] = (int) $attributes['count'];
    
    if( ! empty($attributes['categoryid']) ) {
    	$args['category__in'] = array_map('trim', $attributes['categoryid']);
    } else {
    	$args['category_name'] = $attributes['categoryslug'];
    }
    
    $news = new WP_Query($args);
    
    if( $news->have_posts() ) {
    	$out = '<div class="news-posts-with-thumbnails">';
    	while( $news->have_posts() ) {
    		$news->the_post();
    		...
    	}
    	$out .= '</div>';
    }
    ...
    

    And when this loop is returned, it includes the archived post. The post has the status of “archived” and has a date of 08/15/2022 in the Archive Date metabox. The post is not marked as sticky.

    • This topic was modified 2 years, 3 months ago by jakeparis.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author shawfactor

    (@shawfactor)

    Well firstly the plugins behaviour depends on whether you want to exclude them from the main loop or entirely , this is controlled by the settings.

    Anyway presuming you you want to exclude it from the loop, the issue is likely that this is some sort of custom loop on the front page rather than the main one.

    So I’d suggest just adding the argument:

    $args[‘post_status’] = ‘publish’;

    That should give you just published posts specifically. Give that a go, should work but it’s hard to debug these things remotely

    Thread Starter jakeparis

    (@jakeparis)

    Thanks @shawfactor , I can confirm that explicitly adding the post_status="publish" does solve the problem. This is odd however, because the default for WP_Query is supposed to be only items with the “publish” status (unless you’re logged in, then you get “private” too).

    The client has your config set to “Can Archived Posts be read publicly”:”Yes, but not in the main loop, frontpage, or feed”. I would expect this to apply to any loop of posts, including the core “Recent Posts” block (which I haven’t checked to see how this applies to that).

    Is there perhaps a tweak needed in your plugin, so that your added “archive” status doesn’t get added to the default list of statuses when making a query? I haven’t investigated the code, so I wouldn’t know where to make a suggestion, but maybe this rings a bell for you.

    My query loop is happening inside a shortcode. So, yes, you are correct, this isn’t the main loop, but I would expect the archiving to “just work” in that context anyway.

    Thanks for your help and time.

    • This reply was modified 2 years, 3 months ago by jakeparis.
    Plugin Author shawfactor

    (@shawfactor)

    You are right it should not need publish to be set but I’m glad it works

    Can you please let me know the shortcode you are using as I’lol run sone tests to replicate this (if I can)?

    Thread Starter jakeparis

    (@jakeparis)

    This is a custom shortcode for the theme. You can see it here. You can see on line 47 where I’ve added the “publish” post_status to make it work as expected.

    And they are using it like this: [news-posts categoryid="2" count="6"]

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Arguments needed in Wp_Query to hide archived posts?’ is closed to new replies.