Pagination go to first page if i’m on last post

Here is one idea for the previous post circle: $next_post = get_next_post(); $prev_post = get_previous_post_circle(); where we have defined this function: function get_previous_post_circle($in_same_cat = false, $excluded_categories=””){ $prev_post = get_previous_post($in_same_cat,$excluded_categories); if($prev_post){ return $prev_post; }else{ add_filter(‘get_previous_post_where’,’custom_get_previous_post_where’); $prev_post = get_previous_post($in_same_cat,$excluded_categories); remove_filter(‘get_previous_post_where’,’custom_get_previous_post_where’); if($prev_post){ return $prev_post; }else{ return ”; } } } and the filter function to remove the specific … Read more

Hook into the loop via a plugin, and output something after every X post?

You can try the following: Method 1: We can inject the ads via the the_post action, in the main loop: add_action( ‘loop_start’, ‘wpse_141253_loop_start’ ); function wpse_141253_loop_start( $query ) { if( $query->is_main_query() ) { add_action( ‘the_post’, ‘wpse_141253_the_post’ ); add_action( ‘loop_end’, ‘wpse_141253_loop_end’ ); } } function wpse_141253_the_post() { static $nr = 0; if( 0 === ++$nr % … Read more

wp_list_categories: get latest featured_image of category

You can use a custom Walker, the easiest of which in your case is the Walker_Category and extend it like so: class CategoryThumbnail_Walker extends Walker_Category { // A new element has been stumbled upon and has ended function end_el( &$output, $category, $depth, $args ) { // Output the standard link ending parent::end_el( &$output, $category, $depth, … Read more

Return vs Echo Shortcode

Just define a variable, and concat all html as string and return it. <?php function services_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( ‘slug’ => ”, ), $atts ) ); $html=””; if ( isset( $slug ) ) { $args = array( ‘post_type’ => ‘cbd_services’, ‘name’ => $slug ); // -1 Shows ALL Posts $loop … Read more

Style every four posts differently [duplicate]

Standard Loop: <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content’, get_post_format() ); ?> <?php endwhile; ?> Loop checking for 4th post: <?php $i = 0; while ( have_posts() ) : the_post(); $i++; ?> <?php if(!$i%4): get_template_part( ‘content’, get_post_format() . ‘-4th’ ); ?> <?php else: get_template_part( ‘content’, get_post_format() ); endif; ?> <?php endwhile; … Read more

Sort posts by custom taxonomy name

One solution would be- $terms = get_terms(‘taxonomy-name’); foreach($terms as $term) { $posts = get_posts(array( ‘post_type’ => ‘custom_post_type_name’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘slug’, ‘terms’ => $term->slug ) ), ‘numberposts’ => -1 )); foreach($posts as $post) { // do what you want to do with the posts here } }

Insert/sticky specific post into Loop at specific location

This took a bit of trial and error but I think I got it. I was getting an infinite loop until I added suppress_filters. After that it was short work. function insert_post_wpse_96347($posts) { global $wp_query; $desired_post = 151; if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query(array(‘p’=>$desired_post,’suppress_filters’=>true)); $insert_at = 3; if … Read more