• Resolved TataVostru

    (@tatavostru)


    I want to retrive only first 3 post

    <div class="iflink"><a href="<?php the_permalink()?>" rel="bookmark" title="<?php printf(__('%s'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></div>
    <div class="iflinka"><b>Cu:</b><?php if(get_field('distributie') != ""){foreach(get_field('distributie') as $post_object): ?>
    <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>, <?php endforeach;}?></div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • possibly add a counter for the foreach loop, and break when the conter reaches ‘3’;

    example:

    <div class="iflink"><a href="<?php the_permalink()?>" rel="bookmark" title="<?php printf(__('%s'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></div>
    <div class="iflinka"><b>Cu:</b><?php if(get_field('distributie') != ""){$counter=0;foreach(get_field('distributie') as $post_object): ?>
    <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>, <?php $counter++;if($counter>=3) break; endforeach;}?></div>

    https://php.net/manual/en/control-structures.break.php

    Thread Starter TataVostru

    (@tatavostru)

    thanks, it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Retrive only 3 post from field’ is closed to new replies.