0

Currently, we are getting all posts from a specific category using the following:

$args = array(
    'post_type' => array('post'),
    'cat' => 1247,
    'posts_per_page' => 4
);

What we'd like to do is get all posts from cat 1247 and also from custom post type 'videos', such as:

$args = array(
    'post_type' => array('post', 'videos'),
    'cat' => 1247,
    'posts_per_page' => 4
 );

However, as none of the posts in 'videos' are from category '1247', it's only showing posts from '1247', however I can't seem to find a category for posts in video?

How would we go about achieving what we need to achieve?

  • You won't be able to do this in a single query. As you found out, you are limiting the query by including the cat parameter. Edit: you might be able to do this by using category__not_in instead of cat, but then you'd have to add all of the other category ids to that list - might be hard if you have a bunch of categories. The other solution is to update the custom video post type to use the same categories and assign all of them that particular category - that also may not be feasible. – disinfor Jun 4 at 16:13
  • @disinfor category__not_in might be a shout as I don't have too many categories. Will give it a go. – BN83 Jun 4 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.