Loop – how to get previous/next post for first/last post?

You can loop the slides quite simply: $prev_index = ( $loop->current_post == 0 ) ? count( $loop->posts ) – 1 : $loop->current_post – 1; $next_index = ( $loop->current_post == count( $loop->posts ) – 1 ) ? 0 : $loop->current_post + 1; $prev_post = $loop->posts[ $prev_index ]; $next_post = $loop->posts[ $next_index ]; echo $next_post->post_title; echo $next_post->post_title; … Read more

Add Infinite Scroll to Ajax Loaded Category Query

Update … Here’s the Final Code That Worked for Me This may not be perfect, but it seems to be working well for me with no errors. Feel free to add any suggestions for improvement if you have any. JS Code jQuery(document).ready(function($) { var count = 2; jQuery(“#la-chooser”).change(function() { loadArticlebyCat(this.value); }); function loadArticlebyCat(cat){ data = … Read more

How to handle “the_terms” inside loop

To answer your first question What is the difference between those functions get_terms() returns an array of terms objects that belongs to a specific taxonomy get_the_terms() returns an array of terms belonging to a post the_terms() displays an HTML formatting string of term names belonging to a post Because you need your terms not hyperlinked … Read more

A snippet after every image

Try get_image_tag filter: add_filter(‘get_image_tag’, function($html, $id, $alt, $title, $align, $size) { return $html . ‘<div>some piece of code here</div>’; }, 10, 6); References: get_image_tag() get_image_send_to_editor() wp_ajax_send_attachment_to_editor()

Is it possible to display previous post revision?

First we look into the wp_get_post_autosave function It’s informative to see how the core function wp_get_post_autosave() uses the wp_get_post_revisions() function. It loops over all revisions from $revisions = wp_get_post_revisions( $post_id, array( ‘check_enabled’ => false ) ); and then uses: foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, “{$post_id}-autosave” ) ) … Read more

Query Custom Post by Category

Are these custom taxonomies or the regular categories? if they are just categories you should use: $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘news’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘category_name’ => ‘Alumni’ ); $loop = new WP_Query( $args ); <?php while ( $loop->have_posts() ) : $loop->the_post();?> … <?php endwhile; ?> if you want … Read more

get understrap pagination to work with custom query

the pagination function does nothing with a custom loop That’s because for custom loops or secondary WP_Query instances like your $catquery variable, you need to explicitly tell the function how many pages are available for your custom query. So the $total argument (see the function’s description) should be set to the max_num_pages property of the … Read more