WP_Query pagination not working in admin area

Milo noted that there is no $wp_query object in wp-admin page, so we can get $paged via: $paged = ( $_GET[‘paged’] ) ? $_GET[‘paged’] : 1; Now that we have $paged, we can code our own pagination. I will demonstrate how in its very simplest form. First let’s get maximum pagination pages: $max_pages = $the_query->max_num_pages; … Read more

Search tags in CPTs

This would only work if the keyword exactly matches the tag that you are searching for, and unfortunately, tag data isn’t indexed by WordPress search by default, so that won’t yield anything either. If you want to index the tags and include that in search results you might want to use a plugin. Relevanassi might … Read more

Query Set Order By Author

To order by the authors nicename is not nativly supported by the WP_Query. If you order by author, as you have experienced, you order by the ID of the author. So, you would need to actually go into the SQL clauses and manage this by yourself. This is a quick and dirty hack to do … Read more

How get posts from a subcategory of a category by name?

// Getting Parent ID $parent = get_term_by( ‘name’, ‘Session 2015’, ‘category’); // Checking if SubCategory Exist. $term = term_exists(‘Photos’, ‘category’, $parent->term_id); //if Exist Do the query if ($term !== 0 && $term !== null) { $query = new WP_Query( ‘cat=”.$term[“term_id’] ); } References: term_exists get_term_by

Pagination not working

As I already stated in comments, you should never use query_posts, only use query_posts if you are intended to break your page functionalities. Add query_posts to the very top of your EVIL LIST. query_posts breaks the main query object, the very object that your pagination function relies on. Your pagination function relies on the $max_num_pages … Read more

WP_Query order by date in meta_value

change your args as bellow $args = array( ‘post_type’ => ‘your_post_type’, ‘orderby’ => ‘meta_value’, ‘meta_query’ => array(array(‘key’ => ‘releaseDate’)), ‘order’ => ‘ASC’, ‘paged’ =>$paged, ); If you get the results ordered other way around, change ‘order’ => ‘DESC’, You’ll get the correct order.

Get rewrite result

Have a look at the Action Reference to see generally how requests are processed. After all the loading and init stuff happens, the parse_request action runs when the request is matched against the rewrite rules, and an object is passed containing all the registered query vars and the matched rule and query string. function wpd_parse_request( … Read more

Select random post every day

Note that the posts_orderby filter is not available for get_posts() where suppress_filters is true by default. You can use WP_Query instead: $args = [ ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’, ‘post_type’ => ‘listing’, ‘ignore_sticky_posts’ => true, ]; add_filter( ‘posts_orderby’, ‘force_random_day_seed’ ); $q = new WP_Query( $args ); remove_filter( ‘posts_orderby’, ‘force_random_day_seed’ ); if( $q->have_posts() ) { … Read more

Ignore/Skip default value on orderby menu_order?

You can try the following (untested) mini plugin: <?php /** * Plugin Name: Support for ignoring the default menu order in WP_Query * Description: Uses the _ignore_default_menu_order argument * Plugin URI: http://wordpress.stackexchange.com/a/193291/26350 */ add_filter( ‘posts_where’, function( $where, $q ) { global $wpdb; if( (bool) $q->get( ‘_ignore_default_menu_order’ ) ) { $where .= “AND {$wpdb->posts}.menu_order <> 0”; … Read more

Filter user list that meta_value is empty

I think the use of meta_query is in order: $user_query = new WP_User_Query( array( ‘meta_query’=> array( array( ‘key’=> ‘birthday’, ‘compare’ => ‘NOT EXISTS’ ) ) ) ); Basically, this looks for all users where the meta key of birthday doesn’t have a value ie doesn’t exist. More info about meta queries in WP_User_Query can be … Read more