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

[Resolved] Can I exclude with a custom meta field from a list?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Can I exclude with a custom meta field from a list?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13205
    Xavier
    Participant

    Hello there!

    Since a specific taxonomy can’t be excluded from a list (https://wpshowposts.com/support/topic/exclude-category/) I’m trying to exclude the posts I need to ignore using meta Key and Meta Value in “More settings”.

    But is not working. :´(

    My web site has a number of posts now and it would be cumbersome to add a taxonomy or a custom meta field to all. So I add a field named “exclude” with the value “true” to the posts I want to discard from this specific list.

    My Question: can it be done somehow?

    Thanks!

    #13239
    Tom
    Keymaster

    Hi there,

    You should be able to choose exactly which categories you want to include posts from. This way, you can simply leave the ones you want to exclude un-checked.

    Let me know 🙂

    #13254
    Xavier
    Participant

    Thanks for your quick answer, Tom,

    Well, not ideal since we’re using several taxonomies and in each one, the post We want to exclude from the list share some other term(s) with others that must show up. Of course, we can create another taxonomy and apply to each and one of the posts (some 800) the appropriate term.

    If we can’t exclude employing Custom post Field we’ll try this approach.

    Thanks, Tom

    #13344
    Tom
    Keymaster

    Hmm, it may be possible otherwise.

    Make this change in your wp-show-posts.php file: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de

    Then do this:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $args['meta_query'] => array(
                array(
                    'key' => 'your_custom_field',
                    'value' => 'your value to check',
                    'compare' => '!==',
                )
            );
        }
    
        return $args;
    } );

    You just need to change 123 to your list ID, and adjust the key and value.

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