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

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

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

How to limit get_posts()?

You can use posts_per_page or numberposts. http://codex.wordpress.org/Template_Tags/get_posts#Parameters EDIT: Regarding your edit. You cannot have the posts_per_page different to the LIMIT in the SQL query. get_posts() creates an instance of WP_Query and returns it using the posts_per_page as the LIMIT.

data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}

You can set your own keys in the JSON response array. It can be anything. Take a look at this simple example: add_action( ‘rest_api_init’, function () { register_rest_route( ‘shubham’, ‘/get_the_post/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_posts_by_rest’ ) ); }); // Callback function function get_posts_by_rest( ){ // Get the post id from the URL and … Read more

Check If posts exist in custom post type category, outside of loop

It all boils down to WP_Query in the end even if you use get_posts, here’s my modified version: $hasposts = get_posts(‘post_type=sc-events&category=40’); if( !empty ( $hasposts ) ) { ..// show the drop down menu } or $query = new WP_Query(array( ‘post_type’ => ‘sc-events’, ‘category’ => 40 )); if( $query->have_posts() ){ echo ‘we have posts’; } … Read more

Filtering custom post type query

Yes, you can do that. Just remove the first foreach and give the General category ID and change the code like below- // Initiating shortcode. Place this code to any of your page to get your desired output. add_shortcode( ‘faq_page_content’, ‘the_dramatist_faq_page_content’); /** * Rendering function */ function the_dramatist_faq_page_content() { echo ‘<ul>’; $posts = get_posts( array( … Read more

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