Using Post Indexer With Attachments

Hello,

The Post Indexer dashboard page is showing that 35 attachments have been indexed. I am not sure the correct way to display the attachments.

display_recent_posts_tester('page'); // Works!
display_recent_posts_tester('post'); // Works!
display_recent_posts_tester('attachment'); // Does Not Work!

Here is the function I am using:

function display_recent_posts_tester($myposttype) {
    $myposts = network_query_posts(array('post_type'=>$myposttype,'posts_per_page'=>50, 'orderby'=>'rand'));
    if( network_have_posts() ) {
      echo "<strong>WE HAZ POSTS! </strong>";
      network_the_post();
      foreach($myposts as $mypost){
        var_dump($mypost);
        echo "";
      }
    }
}

Please advise. Thanks!

  • cfs

    The post_status of media attachments is 'inherit'.

    This SQL was failing because it specifies a post type of 'public' or 'private':

    THE BAD:

    SELECT SQL_CALC_FOUND_ROWS bhq_network_posts.BLOG_ID, bhq_network_posts.ID FROM bhq_network_posts WHERE 1=1 AND bhq_network_posts.post_type = 'attachment' AND (bhq_network_posts.post_status = 'publish' OR bhq_network_posts.post_status = 'private') ORDER BY RAND() DESC LIMIT 0, 50

    HERE IS THE FIX WITH POST STATUS 'INHERIT' ADDED:

    SELECT SQL_CALC_FOUND_ROWS bhq_network_posts.BLOG_ID, bhq_network_posts.ID FROM bhq_network_posts WHERE 1=1 AND bhq_network_posts.post_type = 'attachment' AND (bhq_network_posts.post_status = 'publish' OR bhq_network_posts.post_status = 'private' OR bhq_network_posts.post_status = 'inherit') ORDER BY RAND() DESC LIMIT 0, 50

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.