smizmar Posted November 14, 2014 Share Posted November 14, 2014 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: <?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: <?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.) Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 14, 2014 Share Posted November 14, 2014 Not a wordpress user but does the following work? function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'events_categories', 'mycategory1' ); $query->set( 'category_name', 'mycategory2' ); } } add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' ); Quote Link to comment Share on other sites More sharing options...
smizmar Posted November 14, 2014 Author Share Posted November 14, 2014 Nope, that was the first thing I've tried. No error message, but the result is an empty page :-( Thanks for your reply though! :-) Quote Link to comment Share on other sites More sharing options...
maxxd Posted December 9, 2014 Share Posted December 9, 2014 Try this: function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { return $query; } $query->set( 'events_categories', 'mycategory1' ); $query->set( 'category_name', 'mycategory2' ); return $query; } add_filter( 'pre_get_posts', 'childtheme_cat_limited_blog' ); I'm not sure if events categories is a custom taxonomy or not - if it is, I'm not sure the above will work, but there are ways around that too so post back here if it doesn't work. Quote Link to comment Share on other sites More sharing options...
Fedral144 Posted December 11, 2014 Share Posted December 11, 2014 I am taking a form that has been created and now trying to incorporate it into WP. The form is filled out multiple times per session. The form when filled out will generate an ID that is testking.net used to track the form submissions until completed. The problem that I'm running into is that the code is using a URL structure that breaks on the install. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.