How to exclude posts for current user

I’m not entirely sure what the problem is, because you’ve already mentioned all the tools that you need to solve it… Just use pre_get_posts filter, check if the user is logged in, get the IDs of posts he should not see and exclude them in query: function remove_some_posts_for_user( $query ) { if ( ! is_admin() … Read more

Connecting to a different database

But I would like to use my secondary database connection like a standard WordPress query, so that all of the query builder functions are available. Unless the other database is a WordPress database, with the exact same table structure, you can’t. The query builder functions in WordPress are designed and built only to work with … Read more

add_query_arg not work in admin

some_body needs to be run as an action on pre_get_posts. Here’s an example of the entire process of adding new query vars. Pay extra attention to myplugin_pre_get_posts: function myplugin_pre_get_posts( $query ) { … $city = get_query_var( ‘city’ ); … } add_action( ‘pre_get_posts’, ‘myplugin_pre_get_posts’, 1 );

problem with sql query

Your code should look something like this: $this->table_name=”table_name”; $how_much = $this->wpdb->get_var(“SELECT COUNT(*) FROM $this->table_name”); We don’t need to use the prepare method, since this is not meant for table names, more here And also… as you what are trying to do is going not in a good direction… I don’t what to criticize you or … Read more

Query where ANDing slug values not working

You can do this using the WP APIs like this: $args = [ ‘post_type’ => ‘post’, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘your_taxonomy_name’, ‘field’ => ‘slug’, ‘terms’ => array( ‘arizona’, ‘speech-language-pathology’ ), ] ], ]; $query = new WP_Query( $args ); Then you can use $query as you would any standard post … Read more

Yoast primary category query modification

I’m not sure this will fix it, but maybe try using the current category slug for the $current_category variable, instead of single_cat_title(), like so: $term = get_queried_object(); $current_category = $term->slug; This might help because the category_name parameter in WP_Query, despite its name, should be the term slug. single_cat_title() returns the displayed category title, not slug.