Exclude authors IDs from WP_Query

exclude specific authors from WP_Query You can do it like so: $args = array( ‘author__not_in’ => array( 10, 3, 4 ), ); $posts_query = new WP_Query( $args ); But if you meant “from WP_User_Query“, then in WP_User_Query, you should use the exclude parameter, and that array(‘who’ => ‘authors’) shouldn’t be in meta_query: $args = array( … Read more

Undefined $post in wp_query

The most reliable way to get the current post being viewed is not the global $post variable. Instead you should first check is_singular(), and then use get_queried_object() to get the post object, or get_queried_object_id() to just get the ID. if ( ! is_singular() ) { return; } $post_id = get_queried_object_id(); $args = array( ‘post_type’ => … Read more

Appending to existing WP_Query’s meta_query if exists

You can use the WP_Query::get method to get whatever is in the meta query like this: add_action(‘pre_get_posts’,’add_another_meta_query’); function add_another_meta_query($query){ //Be sure to only use the main query on frontend if($query->is_main_query() && !is_admin()){ $meta_query = $query->get(‘meta_query’,array()); $new_meta_query = array(); //now, $meta_query has the meta_query if set (or an array) //check if the old version of meta_query … Read more

get_query_var always returns the default value

In WordPress, query vars are not what you think they are. They are the arguments for the global WP_Query object which processes the main page request. Check the docs for more information. What you need in that particular case is to check the $_GET parameters on the page load. For example: $scoretime = filter_input( INPUT_GET, … Read more

how to load the comment template from a plugin

You can use the comments_template filter to alter which file your CPT will use for comments. function wpse_plugin_comment_template( $comment_template ) { global $post; if ( !( is_singular() && ( have_comments() || ‘open’ == $post->comment_status ) ) ) { // leave the standard comments template for standard post types return; } if($post->post_type == ‘business’){ // assuming … Read more

Hide posts if user is added to it WP_query

Hopefully i understood correctly what you want to achieve here. If you want to exclude all posts that contain get_current_user_id() in the project_users ACF repeater, but at the same time contains has get_current_user_id() in favourite_users, the correct meta query looks like this: ‘meta_query’ => array( ‘relation’ => ‘AND’, array( array( ‘key’ => ‘project_users’, ‘value’ => … Read more

Check if searched number is within the post meta value

Assuming your “property-guests” taxonomies have names like “1”, “2”, “3”, etc.: <?php // Get the number of guests the visitor searched for $requiredGuests = $_POST[‘guests’]; // Get all terms in the “property-guests” taxonomy // (By default, this will only include terms that are assigned to something) $allGuestNumbers = get_terms(array(‘taxonomy’ => ‘property-guests’)); // Create a variable … Read more