How do I combine these 2 queries

I wouldn’t combine the queries, primarily since they’re keying on different meta keys and values. The WP Query API is very powerful, but you’re trying to do some very advanced searching and sorting here. One option would be to write a raw SQL query by hand and pass it into $wpdb->get_results(), but that won’t necessarily … Read more

How to get 4 Posts after the 5 most recent ones

Simple. WordPress provides a function called get_posts() that lets you get posts in any order. Basically, get_posts() will retrieve the 5 most recent posts by default. To get 4 posts, ignoring the 5 most recent, you’d set the numberposts and offset parameters – offset tells the function how many posts to skip. $args = array( … Read more

Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured

It is possible if you shape your meta query to look for the serialized string like this, assuming your array value is always an integer: $params = array( ‘meta_query’ => array( array( ‘key’ => ‘mediSHOP_product_extras’, ‘value’ => ‘s:11:”is_featured”;i:1;’, ‘compare’ => ‘LIKE’ ) ) ); $query = new \WP_Query( $params ); If the array value is … Read more

What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?

If you look at the source of setup_postdata() you’ll find that it requires an object ($post), to be passed, not an array. wp_get_recent_posts() (source), by default (for pre 3.1 backwards compatibilty) returns each post as an array. The second, optional argument, that can be passed to wp_get_recent_posts() can prevent this: $posts = wp_get_recent_posts( $args, OBJECT_K … Read more

SELECT * FROM $wpdb->posts WHERE ID > 160

SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id) LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) WHERE $wpdb->posts.post_type=”post” AND $wpdb->term_taxonomy.taxonomy = ‘post_tag’ AND $wpdb->posts.ID > 160 ORDER BY $wpdb->posts.ID ASC LIMIT 5 $pageposts = $wpdb->get_results($querystr); if ($pageposts): ?> <?php global $post; ?> <?php … Read more

get_posts empty when called via Ajax

To get data from AJAX call you have to echo or print it. In WordPress you should use wp_send_json() function to send data as response to call. function mh_get_addons( $args = array() ) { $defaults = array( ‘posts_per_page’ => -1, ‘orderby’ => ‘post_title’, ‘order’ => ‘DESC’, ‘post_type’ => ‘mh-addon’, ‘post_status’ => ‘publish’ ); $args = … Read more

get_posts from post x(offset=>x) to end

It’s strange, you’d have thought if you disable paging and grab all posts, that you could naturally set an offset to, eg. array( ‘nopaging’ => true, ‘offset’ => 10 ) or array( ‘posts_per_page’ => -1, ‘offset’ => 10 ) or array( ‘numberposts’ => -1, ‘offset’ => 10 ) This unfortunately doesn’t appear to work(bug / … Read more

meta_query date and time comparisons

You are mixing up an older meta syntax with the newer one. I’d suggest you clean that up for readability and for potential compatibility in the future. (WordPress does seem to parse the mixed query correctly though) $args = array( ‘posts_per_page’ => -1, ‘post_type’ => MDJM_EVENT_POSTS, ‘post_status’ => ‘mdjm-approved’, ‘meta_query’ => array( ‘relation’ => ‘AND’, … Read more

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