Home Forums Front-end Issues ACF relationship pagination not working


ACF relationship pagination not working

  • Hi, I’m having a problem adding pagination in ACF relationship. I’m not sure what’s wrong but it’s already showing and the path is correct on the link but it just reload the page and nothing happens.

    here is my code. this is originally added inside a shortcode to be added in elementor template.

    Thank you.

    <?php $related_products = get_field( 'related_products' );
    if ( $related_products ) {
    	global $paged;
    	$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        $args = array( 
            'post_type' => 'product',
    		'fields' => 'ids',
            'post__in'  => $related_products,
    		'posts_per_page' => 4,
        	'paged' => $paged,
        $custom_query = new WP_Query( $args );
        if ( $custom_query->have_posts() ) :  
            while ( $custom_query->have_posts() ) : 
                wc_get_template_part( 'content', 'product' );
    ?><?php //pagination addition
    $total_pages = $custom_query->max_num_pages;
                if ($total_pages > 1){
                    $current_page = max(1, get_query_var('paged'));
                    echo paginate_links(array(
                        'base' => get_pagenum_link(1) . '%_%',
                        'format' => 'page/%#%',
                        'current' => $current_page,
                        'total' => $total_pages,
                        'prev_text'    => __('ยซ prev'),
                        'next_text'    => __('next ยป'),
                } //end pagination ?>
        else : 
        // do something else
        echo "Sorry no slected products right now!";
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.