WP_Error not displaying errors

Actions don’t typically return data, so I doubt you will get this working the way you are trying to. Something like… function cpt_pre_post_publish(){ global $my_error; $my_error = new WP_Error(‘error’, __(‘Error!’ )); } add_action(‘pre_get_posts’, ‘cpt_pre_post_publish’); … should set a variable that you could access in a template file with… global $my_error; var_dump($my_error); It is really not … Read more

Single meta_query query using OR instead of AND in request’s WHERE statement

I believe the shortest and best approach is to (1) modify the query: function search_faqs_metadata($query) { if(!is_admin() && $query->is_main_query()) { if($query->is_search) { $query->set(‘meta_query’, array(array( ‘key’ => ‘_faqs’, ‘value’ => $query->query_vars[‘s’], ‘compare’ => ‘LIKE’ ))); } } } add_action(‘pre_get_posts’, ‘search_faqs_metadata’); and then (2) replace the AND with OR via the get_meta_sql filter: function change_meta_key_where_from_and_to_or($sql) { if(is_search()) … Read more

Include posts from feature category in pre_get_posts

I haven’t run this code so there may be a syntax error, but the gist is to return userfeed-taxonomy with the terms specified that have featured category OR cities-taxonomy with the terms specified and featured category OR anything else that’s not those taxonomies. It’s kind of clunky, maybe there is a better way: $query->set( ‘tax_query’, … Read more

Adding a parameter to the default query

I think the cleanest method here is just run a custom query, get the ID and then remove that post from the main query with post__not_in. You can additionally run a query inside a function and then call the function in your featured section and in pre_get_posts. There is another way, using a global to … Read more