Black Friday sale! Get 25% off WPSP Pro! Discount automatically applied at checkout.

[Resolved] Query two post IDs in one add_filter?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Query two post IDs in one add_filter?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15870
    Greg
    Participant

    Hi guys, I’ve now got filtering by categories and tags working with the code edit to the plugin Tom references in a couple of other threads.

    My question now is if it’s possible to query more than one post ID in a filter snippet? I have a number of lists I would like to filter in the same way (by category within the WP Show Posts list settings) and then via the same tag in the filter – is this the only way I can add multiple lists to the same snippet?

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $args['tag'] = 'post-tag';
        }
    
        if ( 456 === $settings['list_id'] ) {
            $args['tag'] = 'post-tag';
        }
    	
        return $args;
    }, 10, 2 );

    Thanks for the help

    Greg

    #15931
    Tom
    Keymaster

    Might be easier to do this:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        $ids = array(
            123,
            456,
            789,
        );
    
        if ( in_array( $settings['list_id'], $ids ) ) {
            $args['tag'] = 'post-tag';
        }
    	
        return $args;
    }, 10, 2 );
    #15973
    Greg
    Participant

    Perfect, thanks as ever for the help! 🙂

    #15978
    Tom
    Keymaster

    You’re welcome 🙂

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