Home Forums General Issues How to add post per page with relationship


How to add post per page with relationship

  • `I’m trying to figure a way how to make posts per page work. By default shows all. I’ve tried a bunch of ways but no luck even with putting a second query inside the foreach loop.

    From acf documentation

    $eventposts = new WP_Query( array(
    ‘post_type’ => ‘artist’, // This is the name of your post type – change this as required,
    ‘posts_per_page’ => 4,
    ‘order’ => ‘DESC’,

    ‘tax_query’ => array(
    ‘taxonomy’ => ‘location’, // taxonomy name
    ‘field’ => ‘term_id’, // term_id, slug or name
    ‘terms’ => 836, // term id, term slug or term name

    ) );

    while ( $eventposts->have_posts() ) : $eventposts->the_post();
    // The content you want to loop goes in here:

    $featured_posts = get_field(‘relation’);
    if( $featured_posts ): ?>
    <?php foreach( $featured_posts as $post ):

    // Setup this post for WP functions (variable must be named $post).
    setup_postdata($post); ?>
    <a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>
    <span>A custom field from this post: <?php the_field( ‘field_name’ ); ?></span>
    <?php endforeach; ?>
    // Reset the global post object so that the rest of the page works correctly.
    wp_reset_postdata(); ?>
    <?php endif; ?>

    <?php endwhile;

  • Relationship fields do not have “pages”. There is nothing built into the relationship field that could show a certain number of posts with links to show more related posts. You would need to build something yourself like maybe this

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.