How to print the excuted sql right after its execution

The $wpdb object has some properties getting set for that: global $wpdb; // Print last SQL query string echo $wpdb->last_query; // Print last SQL query result echo $wpdb->last_result; // Print last SQL query Error echo $wpdb->last_error; Note: First of all you have to set define( ‘SAVEQUERIES’, true ); in your wp-config.php file at root folder … Read more

Exclude post ID from wp_query

I suppose this was heavy, but to answer your original question, I’ve collected all of the posts id’s in an array in the first loop, and excluded those posts from the second loop using ‘post__not_in’ which expects an array of post id’s <?php $args1 = array(‘category_name’ => ‘test-cat-1’, ‘order’ => ‘ASC’); $q1 = new WP_query($args); … Read more

Pagination when using wp_query?

Replace <!– WHAT GOES HERE?????? –> with the pagination code below: <div class=”pagination”> <?php echo paginate_links( array( ‘base’ => str_replace( 999999999, ‘%#%’, esc_url( get_pagenum_link( 999999999 ) ) ), ‘total’ => $query->max_num_pages, ‘current’ => max( 1, get_query_var( ‘paged’ ) ), ‘format’ => ‘?paged=%#%’, ‘show_all’ => false, ‘type’ => ‘plain’, ‘end_size’ => 2, ‘mid_size’ => 1, ‘prev_next’ … Read more

meta_query with meta values as serialize arrays

No, it is not possible, and could even be dangerous. Serialised data is an attack vector, and a major performance issue. I strongly recommend you unserialise your data and modify your save routine. Something similar to this should convert your data to the new format: $args = array( ‘post_type’ => ‘my-post-type’, ‘meta_key’ => ‘_coordinates’, ‘posts_per_page’ … Read more

wp query to get child pages of current page

You have to change child_of to post_parent and also add post_type => ‘page’: WordPress codex Wp_query Post & Page Parameters <?php $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’ ); $parent = new WP_Query( $args ); if ( $parent->have_posts() ) : ?> <?php while ( … Read more

WP_Query with “post_title LIKE ‘something%'”?

I would solve this with a filter on WP_Query. One that detects an extra query variable and uses that as the prefix of the title. add_filter( ‘posts_where’, ‘wpse18703_posts_where’, 10, 2 ); function wpse18703_posts_where( $where, &$wp_query ) { global $wpdb; if ( $wpse18703_title = $wp_query->get( ‘wpse18703_title’ ) ) { $where .= ‘ AND ‘ . $wpdb->posts … Read more