get_posts query matches too many results

Well, you need to include the type comparison, or alphanumeric comparison is applied here. In this case, you should add ‘type’ => ‘numeric’. Using Your Class Function <?php public function list_related_docs($id){ $docs_args = array( ‘post_type’ => ‘publication’, ‘post_status’ => ‘publish’, ‘posts_per_page’=> -1, ‘orderby’ => ‘meta_value_num title’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘fund_list_order’, ‘limit’ => 4, … Read more

Re-sort get_posts query results

Reordering the way you want is really pretty trivial. Proof of concept: $p = array(1,2,3); var_dump($p); array_push($p,array_shift($p)); var_dump($p); With the WordPress code: $p = get_posts(‘posts_per_page=3’); array_push($p,array_shift($p)); var_dump($p); To make it more interesting, you can do the same with a filter. Since get_posts() uses wp_query() you can use the post_results hook to reorder the results. function … Read more

Get posts by category name

list all the PAGES that are assigned to particular page(s). I’m assuming you mean “particular term(s).” which would be in your clinical-programs taxonomy. You’ll have to do a bit of coding – you need to start a new WP_Query and structure your query as such: $taxPages = new WP_Query( array( ‘post_type’ => ‘YOUR_POSTTYPE_HERE’, ‘clinical-programs’ => … Read more

Get all posts with a certain meta key, except for one with specific title

Unable to test this at the moment, but try something along these lines. Search all posts for your Post Name (Special title), grabbing the ID’s, then utilize post__not_in to exclude those IDs in get_posts. function getAllPostIdsTest(){ global $wpdb; $excluded_posts = $wpdb->get_results(“SELECT id FROM ” . $wpdb->posts . ” WHERE `post_title` LIKE ‘%”Special title”%’ && `post_type` … Read more

Get x recent posts by author?

The function you are using, get_most_recent_post_of_user, won’t work as it only retrieves the latest post from the author. It cannot retieve a list of posts Walks through each of a user’s blogs to find the post with the most recent post_date_gmt. You will most probably be better of using either WP_Query or get_posts to achieve … Read more

Function using get_posts() with tax_query not working when called from functions.php

For testing purposes in your functions.php file, try this – add_action(‘init’, ‘my_test_get_all_bands’, 99); function my_test_get_all_bands(){ echo ‘<pre>’; print_r(get_all_bands()); echo ‘<pre>’; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been registered then the tax_query portion of your get_all_bands() … Read more

get_posts not pulling the correct number of posts

As stated in comments Most probably your posts per page setting for your site is less than 10 One have to remember, get_posts uses WP_Query. Any new instance of WP_Query and the main query (which also uses WP_Query) uses the value set for Blog pages show at most as default for the posts_per_page parameter when … Read more

Multiple posts/pages in one page?

More complex way I use it this way (I’m usually doing one page design, however the method of loading pages is still same). Fo Theme options, I’m using Option tree plugin where my clients could just checkbox which pages should appear there (it’s passed by it’s ID) and than I load it into the script. … Read more

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