0

I am completely stumped on this. The code below allows me to query multiple post types. I break them down like this because of the use of categories. The weird thing is, I only get posts from the post_type = 'post'. The final query I use post__in to establish the posts that I want by ID. If I print out $post_ids, I get the exact IDs that I am looking for. But my final query doesn't give me those IDs. Thoughts??

$postArgs = array(
    'post_type' => 'post',
    'cat' => '16,17,18',
    'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status' => 'publish'
);

$videoArgs = array(
    'post_type' => 'occ-videos',
    'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status' => 'publish'
);

$photoArgs = array(
    'post_type' => 'occ-photography',
    'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status' => 'publish'
);



$docArgs = array(
    'post_type' => 'wpfb_filepage',
    'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status' => 'publish'
);


$posts_query = get_posts($postArgs);
$docs_query = get_posts($docArgs);
$video_query = get_posts($videoArgs);
$photo_query = get_posts($photoArgs);


// start putting the contents in the new object
$all_posts = array_merge($posts_query, $docs_query, $video_query, $photo_query);

$post_ids = wp_list_pluck( $all_posts, 'ID' );//Just get IDs from post objects

print_r($post_ids);


$artArgs = array(
    'posts_per_page' => 20,
    'post_status' => 'publish',
    'orderby' => 'post__in',
    'post__in' => $post_ids);


$artQuery = get_posts($artArgs);

1 Answer 1

1

My understanding is that Wordpress always defaults to the post_type of post. So it's only finding posts that have one of those IDs – and ignoring your custom post types.

Trying adding a line to to your $artArgs

$artArgs = array(
  'post_type' => array('post','page','occ-videos','occ-photography'), //Add this line
  'posts_per_page' => 20,
  'post_status' => 'publish',
  'orderby' => 'post__in',
  'post__in' => $post_ids
);

And add whatever post types you need Wordpress to query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.