PHP code to display posts id-s

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

Viewing 5 posts – 1 through 5 (of 5 total)
  • Anonymous
    #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

    Anonymous
    #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

    Anonymous
    #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)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.