March 2020
Beginner
660 pages
18h 28m
English
We can search posts/custom post types for specific categories or meta values. Add the following code inside the if condition check to limit searching to posts with one category and a specific meta value:
$query->set( 'cat', '55' ); $query->set( 'meta_key', 'wpccp_post_allowed_user' ); $query->set( 'meta_value', '8' );
In this code, we have added a category ID as 55 and a meta key value of 8 for the wpccp_post_allowed_user key in the wp_postmeta table. So, the query will look for posts with a category ID of 55. We can specify any category ID here. Also, it will look for posts limited to users with ID 8. We can also use category and meta key conditions individually without combining them.
Read now
Unlock full access