Skip Navigation

[Resolved] Use a shortcode in a query filter

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 7.72 hours from now. Thank you for your understanding.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 3 months ago.

Author
Posts
#1091503

Tell us what you are trying to do?

I have a simple short code that returns an integer, based on how many child posts exist. I can display that integer fine in the output using the shortcode. But how do I filter by this integer? In other words, I want to only display posts items in the loop from which the shortcode returns greater than zero.

Here's the shortcode:

add_shortcode( 'child-count', 'child_count_func' );
function child_count_func( $atts ){
        $count = 0;
        $child_posts = types_child_posts('product');
        if ($child_posts) {
                $count = count($child_posts);
        }
        return $count;
}

What is the link to your site?

hidden link

#1091869