Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Kapil Chugh

    (@kapilchugh)

    Sure, will work on it.

    Thread Starter SorcRR

    (@sorcrr)

    Ok, thx ??

    Hi, any progress on this? I just ran into the same issue.

    Thought I might get around it by creating a custom nav function using WP_Query to pull the section_name but instead of returning what’s expected I’m getting all posts. Any thoughts on that? I’m happy to contribute my fix code if I can just figure out why WP_Query isn’t working. Here’s the full function for the custom previous link so far:

    function previous_post_link_sorted($section_name, $current_post, $format, $link) {
        $postsQuery = new WP_Query(array(
            'section_name'=>'Work Posts',
            'posts_per_page' => -1,
        ));
        if ($postsQuery->have_posts()) {
        	$last_post = null;
            while ($postsQuery->have_posts()) {
                $postsQuery->the_post();
    
                //var_dump($postsQuery->post);
    
    	        if ($postsQuery->post->ID == $current_post) {
    	            if ($i < ($postsQuery->post_count - 1)) {
    	                $href = '<a href="' . get_permalink($last_post) . '">' . $link . '</a>';
    	                echo str_replace('%link', $href, $format) . "\n";
    	            }
    	        }
    
    	        $last_post = $postsQuery->post->ID;
            }
        }   
    
    }

    This should do it:

    functions.php

    function previous_post_link_sorted($section_name, $current_post, $format, $link) {
    
    	query_posts(array(
            'section_name' => $section_name,
            'posts_per_page' => -1
        ));
        if (have_posts()) {
        	$last_post = null;
            while (have_posts()) {
                the_post();
    
    	        if (get_the_ID() == $current_post) {
    	            if ($i < ($wp_query->post_count - 1)) {
    	            	$href = '<a href="' . get_permalink($last_post) . '">' . $link . '</a>';
    	                echo str_replace('%link', $href, $format) . "\n";
    	            }
    	        }
    
    	        $last_post = get_the_ID();
            }
        }   
    
        wp_reset_query();
    
    }
    
    function next_post_link_sorted($section_name, $current_post, $format, $link) {
    
        query_posts(array(
            'section_name' => $section_name,
            'posts_per_page' => -1
        ));
        if (have_posts()) {
            $use_next_post = false;
            while (have_posts()) {
                the_post();
    
                if ($use_next_post) {
    
                    if ($i < ($wp_query->post_count - 1)) {
                        $href = '<a href="' . get_permalink(get_the_ID()) . '">' . $link . '</a>';
                        echo str_replace('%link', $href, $format) . "\n";
                        break;
                    }
    
                } else if (get_the_ID() == $current_post) {
    
                    $use_next_post = true;
                }
            }
        }   
    
        wp_reset_query();
    
    }

    Usage:

    <span class="nav-prev">
    <?php previous_post_link_sorted('work_posts', get_the_ID(), '<&nbsp;%link', 'PREVIOUS'); ?>
    </span>
    <span  class="nav-next">
    <?php next_post_link_sorted('work_posts', get_the_ID(), '%link>', 'NEXT'); ?>
    </span>

    Plugin Author Kapil Chugh

    (@kapilchugh)

    Thx a lot for posting solution. I’m sorry, I didn’t get time to work on this plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘single post page prev/next post issue’ is closed to new replies.