Querying a custom post type, but not show duplicates

Ahh iv figured out a way to do this: <?php $args = array( ‘post_type’ => ‘classes’, ‘orderby’ => ‘title’, ‘posts_per_page’ => -1 ); $the_query = new WP_Query( $args ); $unique_titles = array(); if( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $title = get_the_title(); if( ! in_array( $title, $unique_cities ) ) : $unique_titles[] = … Read more

exclude pingbacks from wordpress SQL query

You can achieve this by excluding pingback from the comment_type column of wordpress comments table $query = “select wp_posts.*, coalesce(( select max(comment_date) from $wpdb->comments wpc where wpc.comment_post_id = wp_posts.id AND comment_approved = 1 AND post_password = ” AND comment_type NOT IN ( ‘pingback’ ) ), wp_posts.post_date ) as mcomment_date from $wpdb->posts wp_posts where post_type=”post” and … Read more

Waypoints + infinite scroll with custom query

You never seem to populate the $paged variable with a value. Try adding this before the query (from the codex): if ( get_query_var( ‘paged’ ) ) { $paged = get_query_var( ‘paged’ ); } elseif ( get_query_var( ‘page’ ) ) { $paged = get_query_var( ‘page’ ); } else { $paged = 1; } Also, your “load … Read more

WordPress SQL search, how to handle SQL Injection?

The default public search query variable is s but not q. So when you use q, on a vanilla WP install, no posts filtering is done, as expected. You don’t have to take care of possible SQL injections, for the default search query, as it’s taken care of by the core. Here’s an example when … Read more

function query_posts disabling current_page_menu class

The issue is caused by the query_posts function, this function alters the global $wp_query which the menu walker uses to check and add classes like current_page_menu to menu items. A solution would be to write a new custom query and loop through that than using query_posts. $title_slug = strtolower(str_replace( ” “, “-” , the_title_attribute(‘echo=0’) ) … Read more

$wpdb->prepare affecting the query?

You can use the array directly because the $wpdb->prepare() method can be called like vsprintf(), which works like sprintf() but accepts arrays of arguments. $post_types = get_post_types(); unset( $post_types[‘attachment’], $post_types[‘nav_menu_item’] ); global $wpdb; $replace_query = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM $wpdb->posts WHERE post_type IN ( %s )”, $post_types ), ARRAY_A ); The problem with your … Read more

Related Posts function not working

The ultimate answer will be in your server logs, I’m afraid. (You can also turn on debugging in wp-config – sometimes that helps too) But I did notice a few things that hopefully can help you track the issue: <?php // You should not require the $orig_post variable… global $post; // Get the tag ids … Read more