Get a list of posts by specific category

You can also use the following query for getting the results if you have author_id, post_status and cat_id with you. global $wpdb; $author_id = 1; $cat_id = 1; $post_status=”publish”; /* Post Titles */ $search_titles = $wpdb->get_col( “SELECT DISTINCT post_title FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) … Read more

Filter post query to only show direct children of category

I assume that by “direct children of category” you mean “posts directly assigned to the category” and not “posts assigned to child categories of the category specified”. The answer is in the Codex: Display posts that have this category (not children of that category), using category id: $query = new WP_Query( ‘category__in=4’ ); http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters Second, … Read more

Custom SQL Query passing array to WHERE p.id

This is more of a SQL question then a WordPress question. Here are some ideas: You’re most likely looking for this kind of structure: AND p.ID NOT IN (1433, 1344) You should consider using $wp->prepare() if your query depends on some user input. You might also want to replace CURDATE() with a PHP generated date … Read more

Why in this archive page that call query_posts() function show only the last 10 posts?

WordPress by default will only load 10 posts. That can be changed in the admin under Settings->Reading and then setting the amount beside “Blog pages show at most”. You can override that number in your custom queries a couple of ways but I would first recommend against the use of query_posts() ( take a read … Read more

Can’t update multiple rows with $wpdb query

$wpdb->query() returns number of rows affected by the query. It’s returning NULL indicates that there is an error in your query. The problem with your query is that you are updating $wpdb->posts table, but the condition depends on $wpdb->postmeta table. You have to join these tables for the query to work. Another problem is that … Read more

How to overwrite orderby with add_query_var

Use pre_get_posts instead.. function my_archive_query_override( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘rand’ ); } } add_action( ‘pre_get_posts’, ‘my_archive_query_override’ ); For that user selectable part, you can use AJAX to accomplish that.