WP_Query on different site in a multisite setup

Alternative option could be using the Rest API: Example (post): Search for Jane Doe in posts: https://example.com/staffsite/wp-json/wp/v2/posts/?search=jane+doe Example (custom post types): If the public and searchable custom post type (e.g. staff) has show_in_rest set to true then we can search for Jane Doe in staff posts: https://example.com/staffsite/wp-json/wp/v2/staff/?search=jane+doe ps: Somewhat related, if you want to create … Read more

Order posts by date and then by custom field

add_filter(‘posts_orderby’, ‘posts_orderby’); function posts_orderby($orderby_for_query) { global $wpdb; $prefix = $wpdb->prefix; $orderby_for_query = “LEFT(” . $prefix . “posts.post_date, 10) DESC, ” . $orderby_for_query; return $orderby_for_query; } This produces this query: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) AND (wp_postmeta.meta_key = ‘my_post_rating’ ) GROUP BY wp_posts.ID ORDER … Read more

Use post__in and post__not_in together?

post__in and post__not_in are mutually exclusive. Note: you cannot combine post__in and post__not_in in the same query. http://codex.wordpress.org/Class_Reference/WP_Query As your question is written, the solution you reject– that of using array_diff— is the obvious answer. If it is true that that solution won’t work you will need a filter on posts_where (probably) that will provide … Read more

Post queries by latitude and longitude

Close. You need another INNER JOIN and should escape all your variables using $wpdb->prepare. I’ve also included a more efficient Haversine formula (source) to calculate the radius. If you use kilometers, then change the $earth_radius to 6371. Also, a great way to debug is to echo the sql and paste it into phpMyAdmin (or whatever … Read more

WP_query ‘orderby=none’ Problem

You can order them manually after the query is complete: $ids = array (60, 23, 78, 46, 105, 130) $args = array ( ‘posts_per_page’ => -1, ‘post__in’ => $ids, ‘orderby’ => ‘none’ ); $query = new WP_Query ( $args ); $ordered_posts = array(); foreach($ids as $rpid) foreach($query->posts as $index => $fpid) if($fpid->ID === $rpid) $ordered_posts[] … Read more

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