Ordering by meta_key

That happens because of the way WordPress structures the MySQL queries, and the way posts joins postmeta. If a post doesn’t have a value in featured, it won’t join. Here are two options for you: Update the way you’re storing featured to store the value regardless (either ‘1’ or ‘0’). Ensure that every post has … Read more

How to achieve post_status__not_in?

Unfortunately there is no post_status__not_in query argument, but you can simply query for all statuses other than trash & draft: $stati = array_keys( get_post_stati() ); unset( $stati[‘trash’], $stati[‘draft’] ); $stati = array_flip( $stati ); $query->set( ‘post_status’, $stati );

Show all posts even if URL points to a single one

I ended up using the request filter, just like in the documentation: function filterRequest( $request ) { global $single_post_slug; $dummy_query = new WP_Query(); // the query isn’t run if we don’t pass any query vars $dummy_query->parse_query( $request ); if( $dummy_query->is_single() && !$dummy_query->is_admin() ) { $single_post_slug = $request[‘name’]; $request[‘name’] = “”; $request[‘category_name’] = “”; } return … Read more

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

pre_get_posts for exclude category

$caid is unknown inside the function, unless declared global. $caid = ‘-1’; function exclude_category( $query ) { global $caid; if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, $caid ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ ); // Edit Do you need the variable outside the function at all? If not, just move it inside the … Read more