Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro PHP code to display posts id-s

Viewing 5 posts - 1 through 5 (of 5 total)
  • Emil Andreis
    #8970

    Hello, I want to ask is it possible to use some PHP code to output posts id-s. I want to use it instead of [searchandfilter id=”1″ show=”results”] shortcode to display posts id-s like this
    3,7,8,11
    Thank you.

    Ross Moderator
    #8972

    Hey Emil I’m not sure I follow you, can you explain a bit further?

    Thanks

    Emil Andreis
    #8983

    Shortcode [searchandfilter id=”1″ show=”results”] displays search-filter results posts list as per template. I want to display just posts id-s separated by comas. So the search-filter results should look:
    3,4,7,21

    Emil Andreis
    #8986

    Just found the solution with this code used in a template.

    <?php
    if( $query->have_posts() ) {
       $list = array();
       while ($query->have_posts()) : $query->the_post();
          $item = get_the_ID();
          if ($item) $list[] = "$item";
       endwhile;
       echo implode(',',$list) ;
    }
    ?>
    Ross Moderator
    #9030

    Perfect 🙂

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

You must be logged in to reply to this topic.