WP_Query to get posts in a specific category and post format

Two problems i see: change aside to post-format-aside and since you are using foreach loop change new WP_Query( $singargs ); to get_posts( $singargs ); so your code sould look like this: <?php $singargs = array( ‘numberposts’ => 1, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array ( … Read more

Update Loop with Form

Yes, AJAX is the way to go. Basically, you can write your own callback function for WP’s ajax hook in your theme’s functions.php file. And then your function can return data in any format you choose. I generally return JSON. I’ll walk you through setting it up. First, since it doesn’t appear that your visitors … Read more

Paginated HTML Sitemap

Haven’t tested this, but here you go, lemmie know how it works. You’ll needa do your own pagination links, but that should be pretty straightforward //pagination $offset=”0″; $no_of_posts = the_posts_per_page( false ); //Number of posts to display on each page if (preg_match( ‘/page/’, $_SERVER[‘REQUEST_URI’] ) ) { $uri = explode( “https://wordpress.stackexchange.com/”, $_SERVER[‘REQUEST_URI’] ); foreach ( … Read more

Custom WP Query from meta_value stored as serialised array

If you’re inside the while loop, use get_the_ID(). // returns an array as this is a multicheck field in Magic Fields 2 if(get_post_meta(get_the_ID(), ‘services’, true)){ $services = get_post_meta(get_the_ID(), ‘services’, true); $services = maybe_unserialize($services); // foreach item in the array foreach ($services as $service) { if ( sanitize_title($service_title) == sanitize_title($service) ) { echo ‘<p>’ . esc_attr($service) … Read more

How to use Meta Value Compare in WP_Query For Max and Min numbers

This looks right, I have very similar code that works as expected: function price_query_test() { update_post_meta( 7, ‘_price’, 10 ); update_post_meta( 12, ‘_price’, 20 ); update_post_meta( 18, ‘_price’, 30 ); update_post_meta( 72, ‘_price’, 40 ); $test = new WP_Query( array( ‘post_type’ => ‘page’, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array( ’10’, ’25’ … Read more

wp_query() get_col error

UPDATE, Correct Answer: The core WordPress functions are inaccessible at time when using AJAX calls. The proper way to handle this is covered in “AJAX in Plugins” on the Codex. Original answer that didn’t solve the issue but might be interesting for others some day. Here’s an alternate way that avoids having to directly query … Read more

Query by custom dates in UNIX Time

PHP has a built-in date() function that formats Date-objects. In your case, you would use it as follows: echo date(‘Y’, 1322697600); Since you’re using these query arguments to build up an array of posts, and you want to filter specifically on that, I’d recommend building a function that triggers the loop based on your desired … Read more

Pagination stops at page 6

Trying to use pagination from a different query is always fraught with potential disaster. next_posts_link accepts a second argument, $max_pages, which may solve your issue if you pass it properly: next_posts_link( __( ‘Next’), $idxloop->max_num_pages ); However, the real answer to this question is to adjust your query before the template. Adjusting the default query via … Read more

Minimising number of queries on a page when using Advanced Custom Fields

Performance optimization doesn’t really work in vaccum, it takes hands-on profiling an looking for actual bottle necks (which often turn out to be different from perceived ones). But it general there are several approaches to the need of lots of database data: Optimize fetching from database, for example by concatenating multiple requests into retrieving single … Read more