get_query_var function not working at all

WordPress doesn’t automatically add all query string params ($_GET params) as query_vars. When Query Var somevar is not registered: example.com/some-page/?somevar=hello – WordPress ignores somevar When Query Var somevar is registered: example.com/some-page/?somevar=hello – WordPress stores the value of this param in the $wp_query->query_vars array The difference between registering that variable with WordPress is whether the value … Read more

WP_Query: get 3 random posts from 10 latest

There’s one way with: $args = [ ‘post_type’ => ‘post’, ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘no_found_rows’ => ‘true’, ‘_shuffle_and_pick’ => 3 // <– our custom argument ]; $query = new \WP_Query( $args ); where the custom _shuffle_and_pick attribute is supported by this demo plugin: <?php /** * Plugin Name: Support for … Read more

Exclude or Include category ids in WP_Query

As you probably know it, categories are taxonomies. When you use the arguments such as category__in, it will add a tax query to your WP_Query(). So, your situation would be something like this: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( … Read more

Prevent pre_get_posts filter on specific post type

Improve your conditional to include a check for post type being queried. It can be done via WP_Query::get method So, where you have if ( !is_admin() ){ $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); $query->set( ‘meta_value’, $city ); return; } replace with if ( ! is_admin() && in_array ( $query->get(‘post_type’), array(‘event’,’venue’) ) ) { $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); … Read more

Order by DESC, ASC in custom WP_Query

Try this: $args = array( ‘post_type’ => ‘post’, ‘meta_key’ => ‘pb_issue_featured’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘posts_per_page’ => $posts, ‘paged’ => $paged, ‘paged’ => 1, ‘meta_query’ => array( array( ‘key’ => ‘headline’, ‘value’ => 1, ‘compare’ => ‘!=’ ) ) ); add_filter( ‘posts_orderby’, ‘filter_query’ ); $q = new WP_Query($args); remove_filter( ‘posts_orderby’, ‘filter_query’ ); function … Read more

Loop within a loop?

You can create any number of loops as you wish by creating more WP_Query objects $query = new WP_Query($args); while ($query->have_posts()) : // initialization for $inner_args & backup the current global $post $inner_query = new WP_Query($inner_args); while ($inner_query->have_posts()) : // do something endwhile; // restore the global $post from the previously created backup endwhile; EXPLANATION … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)