For-Loop iterates only 5 times but there are more items than 5

Support MB Views For-Loop iterates only 5 times but there are more items than 5Resolved

  • This topic has 2 replies, 2 voices, and was last updated 1 year ago by DufflDuffl.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45086
    DufflDuffl
    Participant

    Hi!

    I am using the following code to display a list of related posts. This works well - but will only show 5 posts. There should be 11, not 5.
    When I add a new related post in backend, this newest one is added to the 5 but another one will drop out so the max number of 5 remains the same. I have no Idea why that is so. Can you help?
    Thank you!

    {% set current_post_id = mb.get_the_ID() %}
    
    {% set args = { post_type: 'my-job', relationship: { id: 'post-to-job', from: current_post_id } } %}
    {% set job_posts = mb.get_posts( args ) %}
    {% for job_post in job_posts %}
      Related Job: {{ job_post.post_title }} <br />
    {% endfor %}
    #45095
    PeterPeter
    Moderator

    Hello,

    You can set the number of posts in admin area > Settings > Reading > Blog pages show at most. Or add the setting posts_per_page to the query args:

    {% set args = { post_type: 'my-job', posts_per_page: 8, relationship: { id: 'post-to-job', from: current_post_id } } %}
    

    Following the documentation https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters

    #45096
    DufflDuffl
    Participant

    Thank you this is great!

    For your interest: Setting "Blog pages show" in WP backend did not change anything, however adding the setting to the query args works perfectly!

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