Merging two queries - a little help, please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smizmar
Forum Newbie
Posts: 1
Joined: Sat Nov 15, 2014 4:04 am

Merging two queries - a little help, please

Post by smizmar »

Now this must be easy enough, but I'm a noob so go easy on me, please :-)

I have two pieces of code and they're working well on their own. All I need is to put these two conditions into one query.

The first one:

Code: Select all

<?php
function childtheme_cat_limited_blog( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'events_categories', 'mycategory1' );
    }
}
add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' );
?>
And the second:

Code: Select all

<?php
function childtheme_cat_limited_blog( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'category_name', 'mycategory2' );
    }
}
add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' );
?>
I'm sure it's a piece a cake for you guys, but I can't figure it out for the life of me, so any help would be greatly appreciated!

Thank you!

(My goal is here to display posts from two categories on a homepage of a Wordpress site, but to complicate things the two categories are from two different post types.)
Post Reply