WP_Query and name__in

The parameter is not supported by WordPress core, but you can implement it using a filter on ‘posts_where’: // require PHP 5.3+ add_action( ‘posts_where’, function( $where, $query ) { if ( isset( $query->query[‘name__in’] ) && is_array( $query->query[‘name__in’] ) ) { global $wpdb; $names = array_filter( array_map( function( $name ) use( $wpdb ) { $sane = … Read more

Pagination custom query

This is a local/global variable problem. It can be solved either by changing the pagination function to work with local variable, or by promoting the local variable into global scope. As you are using wp_reset_postdata(), i guess you want to keep the original query. Change the pagination function to accept arguments – if ( ! … Read more

WP_Query to work with custom view

Use a custom view in the front-end: You can try to modify the SELECT queries in the front-end with the following (alpha) plugin: <?php /** * Plugin Name: wpdb – a custom SELECT view for the wp_posts table on the front-end * Version: alpha */ ! is_admin() && add_filter( ‘query’, function( $query ) { global … Read more

Query posts distinct authors

With what you are asking, it is really difficult to come up with some performant easy way that is also reliable. As @birgire already stated, his solution is not reliable, but from tests, it seem to be the fastest clocking in at 2 db queries in about 0.015s average. From a quick discussion between @birgire … Read more

How to filter sql only for a specific post type

As @bonger said, let your filters accept a second argument, which will be the instance of WP_Query that’s executing the filter, and check it is indeed the main query for an event: function single_posts_fields( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_singular( ‘event’ ) ) { // Do your stuff } } add_filter( ‘posts_fields’, … Read more

Listing posts with wp-cli

the first request doesn’t show any custom post type (polylang_mo is a custom post type) polylang_mo is a private custom post type so unless I explicitly request this post type, it won’t be included. the second request shows only 1 page (instead of 3) Polylang was actually filtering the results. Adding –skip-plugins=polylang makes the 3 … Read more

Get_post() with meta_key when compare is a date

I think you have error in your query. Please try this: $posts = get_posts(array( ‘post_type’ => ‘events’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘meta_key’ => ‘from_datetime’, ‘type’ => ‘DATETIME’, // You can also try changing it to TIME or DATE if it doesn’t work ‘meta_value’ => date( “F d, Y g:i a” ), ‘meta_compare’ => … Read more

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