• Hello, I would really appretiate any assistance with my issue please.

    In my templete pages I have a page that lists posts of a certain category then when one is clicked I have it display the post and post meta content using a longer version of this code

    $this_post_id = $post->ID;
    
    if(empty($this_post_id)) {
    
    	$page = get_page($post->ID);
    	$this_post_id = $page->ID;
    
    } 
    
    $wp_cover_image = esc_attr(get_post_meta($post->ID, 'wp_cover_image',true));
    $wp_fullname = esc_attr(get_post_meta($post->ID, 'wp_fullname',true));
    
    wp_reset_query();

    What I would like to achieve is then right after that find the logged in user’s id and query an attachment posted by the current user using folowing code

    $current_user = get_current_user_id();
    
    $query = new WP_Query(array('post_type' => 'attachment', 'posts_per_page' =>'1', 'post_status' => 'publish, draft, pending', 'author' => $current_user) );

    For some reason this query doesnt supply me with the correct infomation when I run a loop on it. I conclude that its not query the right thing I think.

    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

    Basically I would like to run another query for the logged in user to get their attachments, after I get the current viewed post data.

    Any assistance will be highly appreciated!

    Thank you in advance!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The problem with your query is the ‘post_status’ argument. First of all, multiple arguments should be in an array:
    'post_status' => array('publish', 'draft', 'pending'),

    More importantly, attachments inherit their status from the parent, so you will never get any attachments unless the status is ‘inherit’. To get the actual status you need the status of the parent. Since you want all statuses except revisions and revisions are never parents of attachments, you can simply omit the post_type argument.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple queries on one page dont work’ is closed to new replies.