Manually build WP_Query

If you are using Relevanssi, it is messing with the native search (don’t know exactly at which point), thus, the standard query doesn’t work. I have tested a solution, according to what I read in the plugin’s page, and it seems to do the trick. Just run the relevanssi function to append the results to … Read more

Show recent posts from excluded category

Pieter Goosen solved the issue with with this suggestion. if ( $query->is_home() || $query->is_archive() ) Should be: if (!is_admin() && $query->is_main_query() && ( $query->is_home() || $query->is_archive() ) ) Then explains why this solution worked: is_main_query() only returns true in the main query. pre_get_posts alters all queries back end and front end, there is no designation … Read more

Using URL variables on a custom WP_Query

WordPress doesn’t handle this logic qutomatically so you will have do do it manually. What you need to do is: Read the url parameter with get_query_var( ‘category_name’ ); injects it in your custom WP_Query: $custom_query_args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => … Read more

How To Loop Through list with Custom Post Types

Maybe this could be useful. I used it on my own site to display a list of thumbnails. <?php // check if there’s a thumbnail if ( has_post_thumbnail($post->ID)) { //show thumbnail echo ‘get_the_post_thumbnail($post->ID, ‘thumbnail’ , array(‘class’ => “img-responsive yourClass”)); } else { //show another image if there’s not a thumb echo ‘<img class=”img-responsive” src=”‘.get_template_directory_uri().’/MISSING-PHOTOS.jpg”>’; } … Read more

Custom pagination (Title, date and teaser)

I assume you’re talking about single posts, not archives – get_next_posts_link gets the next archive page, get_next_post_link gets the post next to the current one (note the plural difference). If so, the next/previous post link functions are just wrappers for get_adjacent_post(): <?php if ( $the_query->max_num_pages > 1 ) : ?> <nav class=”prev-next-posts”> <?php if ( … Read more