Articles of get posts

get_posts – find out if querystring was crap and fallback is used

If we pass a String to functions like get_posts, and that string is not a meaningful querystring (for Example get_posts(‘ ‘)), the function returns the results of the default query (the last five posts or such). Is it possible either to suppress this behaviour or – even better – to find out, if the string […]

Advanced Custom Fields: Post Object – Not returning data

I have a custom post type called “Training” with an archive page (archive-training.php). I have another custom post type called “Courses”. I am using Advanced Custom Fields: Post Object to link “Courses” posts to “Training” posts via a single select dropdown on the “Training” edit screen (ie. each “Training” post has one related “Courses” post). […]

How to query posts to include specific pages of one post type, and all pages of another post type?

I’m having trouble figuring out how to query all posts from the post type “events”, as well as including four specific pages in the loop. If I use the “include” parameter, it only returns the specified pages. I figure I can use “exclude” to keep out what I don’t want, but that’s 50+ pages. Is […]

WordPress count child posts of each parent custom post type and use in json array for google maps jquery plugin

So i have been looking for a couple of days now and cant find a solution to this anywhere. It is a fairly bespoke request from a client… I am using a jQuery google maps plugin to add markers for each post (area) that the admin creates using a custom meta box with lat and […]

Get total posts found, but while using limit for pagination? get_posts

I have a ton of posts that I need to get the IDs of based on a custom taxonomy search. As it’s used for pagination, I also need to get the total posts without a limit, but I’m not sure how. I use the following get_posts to find them: $args = array(‘posts_per_page’ => $limit, ‘offset’ […]

use get_posts to get custom field data, but in one array

I’ve run a get_posts query in WordPress and need to pull a pair of custom fields and get all of them into one array. The get_posts query provides an array of posts, but when I use foreach to access the custom fields, I end up with separate arrays for each result. The Query $c_query = […]

Secondary Query Is Breaking Main Query

I registered a Custom Post type called “quote” and I am trying to show a single random quote on every page of my WordPress site. I’m pulling out a single quote with the following code: $args = array( ‘post_type’ => ‘quote’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’ ); $posts = get_posts( $args ); //The code […]

meta_query date and time comparisons

I am trying to query my posts against the value of 2 custom meta_keys… ‘_mdjm_event_date’ formatted as Y-M-D (2015-05-13) ‘_mdjm_event_finish’ formatted as H:i:s (23:35:00) Here is my query… $args = array( ‘posts_per_page’ => -1, ‘post_type’ => MDJM_EVENT_POSTS, ‘post_status’ => ‘mdjm-approved’, ‘meta_key’ => ‘_mdjm_event_date’, ‘meta_value’ => date( ‘Y-m-d’ ), ‘meta_compare’ => ‘<=’, ‘meta_type’ => ‘date’, ‘meta_query’ […]

How to remove 'GROUP BY' from SQL query produced from get_posts?

WordPress, Archive Cateory page. From default WP_Query->get_posts() we are getting something like this: SELECT wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (5) ) AND wp_posts.post_type = ‘post’ AND ((wp_posts.post_status = ‘publish’)) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 40 I want to remove this: […]

Shortcode for display posts on home page show only one post

Need to display 3 posts. I created this code: add_shortcode(‘projects’, ‘projects_shortcode’); function projects_shortcode($atts, $content){ extract(shortcode_atts(array( ‘post_type’ => ‘project’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 3, ‘caller_get_posts’ => 1 ), $atts)); $args = array( ‘post_type’ => $post_type, ‘post_status’ => $post_status, ‘posts_per_page’ => $posts_per_page ); global $post; $posts = new WP_Query($args); $out = ”; if ($posts->have_posts()) while ($posts->have_posts()): […]