WordPress tax_query “and” operator not functioning as desired

not tested but give this a shot ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘image_tag’, ‘field’ => ‘term_id’, ‘terms’ => 25, ‘operator’ => ‘IN’, ), array( ‘taxonomy’ => ‘image_tag’, ‘field’ => ‘term_id’, ‘terms’ => 41, ‘operator’ => ‘IN’, ) ), OR ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘image_tag’, ‘field’ => … Read more

Meta query with string starting like pattern

You could try the REGEXP version: ‘meta_query’ => array( array( ‘key’ => ’email_address’, ‘value’ => ‘^hello@’, ‘compare’ => ‘REGEXP’, ) ) where ^ matches the beginning of a string. You can check the MYSQL reference on REGEXP here for more info. Notice that these are the possible values of the meta compare parameter: ‘=’, ‘!=’, … Read more

WordPress Pagination Not Working – Always Showing First Pages Content

Why your current code fails Your always getting the content of the first page, because the string of parameters passed to query_posts being encapsulated in single quotes prevents variables (as well as escape sequences for special characters other than $) to be expanded. query_posts(“post_type=videos&posts_per_page=9&paged=$paged”); would take care of that problem. query_posts(‘post_type=videos&posts_per_page=9&paged=’.$paged); would also. And finally, … Read more

WP_Query orderby date not working

This will definitely work….It worked for me… $username = get_the_author_meta( ‘login’, $author_id ); $args = array( ‘post_type’ => ‘any’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘suppress_filters’ => true, ‘tax_query’ => array( array( ‘taxonomy’ => ‘author’, ‘field’ => ‘name’, ‘terms’ => $username ) ) ); $query = new WP_Query( $args );

How to query for most viewed posts and show top 5

View this section of the Codex to learn how to create a custom query: http://codex.wordpress.org/Class_Reference/WP_Query Your query will be something like: $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘posts_per_page’ => 5 ) ); By default, the ordering will be highest to lowest, thus giving you the “top” 5.

WP Query Args – Title or Meta Value

Note that the relation part in the meta_query argument, is only used to define the relation between the sub meta queries. You can try this setup: $args = [ ‘_meta_or_title’ => $thesearch, // Our new custom argument! ‘meta_query’ => [ [ ‘key’ => ‘model_name’, ‘value’ => $thesearch, ‘compare’ => ‘like’ ] ], ]; where we … Read more