Display posts from an array of ID’s

if you set the fields parameter to ids you will get an array of ids instead of unneeded post data ex: $ongoing_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_ongoingPromotion’, ‘meta_value’ => 1, ‘fields’ => ‘ids’ ); $current_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_endDate’, ‘meta_value’ => date(“Y/m/d”), ‘meta_compare’ => ‘>=’, ‘orderby’ => ‘meta_value’, … Read more

Custom query does not find pages

This is not the place to use query_posts. query_posts should only be used if you need to change the main loop. There is also no need to reset the query and your missing endif on both loops. I would use get_pages instead of running a new WP_Query. $pages = get_pages(); foreach ( $pages as $page … Read more

wpquery via ajax

The accepted answer on this post: Ajax and autocomplete does an extremely good job of showing exactly how to integrate an ajax call within WordPress.

WP_Query with 2 genres

Something along these lines should work: $myposts = new WP_Query( array( ‘post_type’ => ‘widgets’, ‘post__not_in’ => array($wp_query->post->ID), ‘tax_query’ => array( array( ‘taxonomy’ => ‘genre’, ‘field’ => ‘slug’, ‘terms’ => array( ‘styleA’, ‘styleB’ ) ) ) ) ); I’m not sure if you need to add ‘relation’ => ‘OR’, after line 4, so try it with/without … Read more

how to translate countries output from wp database?

you need to have the actual translations somewhere in a .mo file. for your plugin / theme. 1) when you setup the codes, you can also “mark them for translation” http://codex.wordpress.org/I18n_for_WordPress_Developers#Marking_Strings_for_Translation 2) create the translations for the languages somehow – various tools. eg this one: http://wordpress.org/extend/plugins/codestyling-localization/ 3) in your plugin must tell wp to load … Read more

Query not sorting DESC

if you want to order it DESC put DESC in your query. $postslist = new WP_Query(‘meta_key=Ordermetakey&orderby=meta_value_num&order=DESC&posts_per_page=5’);

Ascending order has strange effects on wordpress loop

It seems the problem is solved by adding ‘posts_per_page’ => -1 which forces WordPress to show all posts matching the parameters. Here’s my final code: array ( ‘post_type’ => ‘symposia_program’, ‘days’ => $progDay, ‘meta_key’ => ‘class_number’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1 );

Avoid WP_Query’s duplicate posts with taxonomies

Pass the post ID from the first query as a post__not_in parameter to exclude it from the second query. $nature_loop_1 = new WP_Query( array ( ‘category_name’ => ‘nature’, ‘tax_query’ => array ( array ( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => ‘sidebar-highlight’, ‘operator’ => ‘IN’ ) ), ) ); $exclude = $nature_loop_1->post->ID; $nature_loop_2 = … Read more