[Resolved] remove category with function php tom

Home Forums Support [Resolved] remove category with function php tom

Home Forums Support remove category with function php tom

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1279316
    alexis

    I found this code that I customized (@tom unsborne) as I wanted. How to include category exclusion. I only want the category related to the article in the next and previous article function. If possible have something dynamic. Examples of articles from such categories I find only articles from the same category. A snippet for the whole site. If this is possible please

    <div id="post-nav">
        <ul class="flex">
    	<?php global $post;
        $prevPost = get_previous_post(false);
        $post_type = get_post_type();
        
            if($prevPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $prevPost->ID,
                    'post_type' => $post_type,
                );
                $prevPost = get_posts($args);
                foreach ($prevPost as $post) {
                    setup_postdata($post);
        ?>
            <li>
            <a class="post-previous" href="<?php the_permalink(); ?>" rel="prev">
            <strong><?php the_title(); ?></strong><span>Mariage précédent</span>
            </a>
            </li>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
             
            $nextPost = get_next_post(false);
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID,
                    'post_type' => $post_type,
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>
            <li>
            <a class="post-next" href="<?php the_permalink(); ?>" rel="next">
            <strong><?php the_title(); ?></strong><span>Mariage suivant</span>
            </a>
            </li>
    
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
        ?>
        </ul>
    </div>
    
    
    #1279490
    David
    Staff
    Customer Support

    Hi there,

    change the false to true in these two lines:

    $prevPost = get_previous_post(false);
    
    $nextPost = get_next_post(false);
    #1280219
    alexis

    Perfect! Thank you David !

    #1280444
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.