And why should it work?
parse_query
is an action, not a filter. This action takes $query
(WP_Query
object) as argument and lets you modify it.
Now, take a look at your code if slug equals 3:
$sql12 = "SELECT * FROM wp_posts WHERE ID IN(SELECT post_id FROM wp_postmeta WHERE meta_key='userlimit' and meta_value > 0)";
$results = $wpdb->get_results($sql12);
return $results;
You don’t modify $query
object, so this code won’t affect the queried posts.
If I understand your intention correctly, you want to get all posts, where value of meta userlimit
is greater than 0? In such case you have to modify $query
this way:
elseif($_GET['slug']== "3")
{
$query->set( 'meta_key', 'userlimit' );
$query->set( 'meta_value_num', 0 );
$query->set( 'meta_compare', '>' );
}
PS. Also you shouldn’t modify query_vars
directly for other cases. Use setter function like in the code above instead.