Search / Filter posts on Title/Content OR Tags

I worked it out myself.. The query I was looking goes like this: SELECT * FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms WHERE ($wpdb->terms.name LIKE ‘%$s%’ OR $wpdb->terms.slug LIKE ‘%$s%’ OR $wpdb->posts.post_content LIKE ‘%$s%’ OR $wpdb->posts.post_title LIKE ‘%$s%’) AND $wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id AND $wpdb->posts.post_status=”publish” AND $wpdb->posts.post_type=”products” ORDER BY $wpdb->posts.post_date … Read more

WP_Query Pagination on multiple-loop page breaks WP or doesn’t show up

Why can’t you write custom pagination? function theme_get_next_posts_link($query, $label = null, $max_page = 0) { global $paged; if(!$max_page) $max_page = $query->max_num_pages; if(!$paged) $paged = 1; $nextpage = intval($paged) + 1; if(null === $label) $label = “Older Posts”; if(!is_single() && $nextpage <= $max_page): $attr = apply_filters( ‘next_posts_link_attributes’, ” ); echo ‘<a class=”page-l” href=”‘ . next_posts( $max_page, … Read more

Query multiple meta values

You code is generating a broken meta_query. You code will produce something like this: array(1) { [“meta_query”]=> array(2) { [0]=> array(2) { [“relation”]=> string(2) “OR” [0]=> array(3) { [“key”]=> string(4) “test” [“value”]=> string(10) “test_value” [“compare”]=> string(4) “LIKE” } } } It should look like this: array(1) { [“meta_query”]=> array(2) { [“relation”]=> string(2) “OR” [0]=> array(3) … Read more

Ajax load more button in Recent posts widget

Look at WordPress’s documentation on AJAX In your theme or plugin, you’ll want to have code like: add_action(‘wp_ajax_my_load_recent’, ‘my_load_recent_posts’); add_action(‘wp_ajax_nopriv_my_load_recent’, ‘my_load_recent_posts’); function my_load_recent_posts() { $args = array( /* Arguments go here, i.e. how many posts to get */ ); query_posts($args); /* [1] */ /* Header wrap output */ if (have_posts()) : while (have_posts()) : the_post(); … Read more

Filtering WP_Query

I rewrote the code and now it works The loop: $args = array(‘post_type’ => ‘artist’); $wp_query = new WP_Query( array_merge( $args, array(‘nopaging’ => true) ) ); The filter: function theme_posts_orderby( $orderby, $query ) { if ($query->query_vars[‘post_type’] == ‘artist’) { // order artists by last name $orderby = “RIGHT(post_title, LOCATE(‘ ‘, REVERSE(post_title)) – 1) ASC”; } … Read more

How do I run through a WordPress loop called from a filter function?

When using a custom query, in order to access the $post information, you need to reference post as a class variable the custom WP_Query. Since you constructed the query as: $hw_selectbox_query = new WP_Query($hw_selectbox_args); Then you would access the post variable of $hw_selectbox_query, like so: var_dump($hw_selectbox_query->post); This will give you the information you need / … Read more

Most commented last 24h, week, month, year and all time – posts_where

Where? The WP_Comment_Query class has the following filter for its clauses: $pieces = array( ‘fields’, ‘join’, ‘where’, ‘orderby’, ‘order’, ‘limits’, ‘groupby’ ); $clauses = apply_filters_ref_array( ‘comments_clauses’, array( compact( $pieces ), &$this ) ); That means you can hook into comments_clauses and filter the $clauses[‘where’] part. How? Since WP 3.7, we got a WP_Date_Query class. It … Read more