[Support request] Combine Conditions

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Combine Conditions

  • This topic has 21 replies, 2 voices, and was last updated 3 months ago by Tom.
Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #18454
    Philip
    Participant

    Is there any way to combine conditions for a list? For example, I’d love to be able to specify to pull posts from a specified category that ALSO have a specified tag. I’m not seeing this, but hoping that there might be a workaround or some way to accomplish it.

    Thanks.

    #18468
    Tom
    Keymaster
    #18478
    Philip
    Participant

    Thank you, this seems like a perfect solution, but no matter what I try, the settings never seem to have any effect.

    I’ve tried setting both fields via the settings and neither in the Dashboard, as well as setting each via the settings and the other in the Dashboard. The one I set in the Dashboard is the only one to ever have any effect – its as if the settings in the shortcode aren’t even there. I’ve also tried using both the category/tag names, as well as their IDs in the settings. For example, I’ve tried:

    [wp_show_posts id="93" settings="category__and=styletag__in=homepage"]
    [wp_show_posts id="93" settings="category__and=8tag__in=68"]
    [wp_show_posts id="93" settings="category__and=style"]
    [wp_show_posts id="93" settings="8tag__in=68"]
    etc.

    I noticed in the other post the “category_in” only had one underscore, while according to the WP reference it should have two. So I fixed that – but either way, it does nothing.

    Any idea what I’m doing wrong here?

    #18480
    Philip
    Participant

    Sorry that code did not come through right. This is what I’ve tried:

    [wp_show_posts id="93" settings="category__and=style&tag__in=homepage"]
    [wp_show_posts id="93" settings="category__and=8&tag__in=68"]
    [wp_show_posts id="93" settings="category__and=style"]
    [wp_show_posts id="93" settings="tag__in=68"]
    #18500
    Tom
    Keymaster

    Ah, think I see the issue. The settings don’t have all of the parameters that the queries have.

    Something like this will need to wait until WPSP 1.2 so we can filter the query for specific lists, unfortunately.

    #18517
    Philip
    Participant

    Is there anywhere I can see what parameters the settings does have?

    Any other way you can think of to get this done? Or any estimate on when 1.2 might be coming?

    Thanks

    #18529
    Tom
    Keymaster

    You can find them here: https://github.com/tomusborne/wp-show-posts/blob/master/wp-show-posts.php#L97-L145

    This is the line that needs updating in the current version: https://github.com/tomusborne/wp-show-posts/blob/master/wp-show-posts.php#L383

    It needs to look like this: https://github.com/tomusborne/wp-show-posts/blob/release/1.2/wp-show-posts.php#L391

    Then we use this filter:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $args['category__and'] = 8;
            $args['tag__in] = 68;
        }
    
        return $args;
    }, 10, 2 );

    You just need to update the 123 with the ID of the list.

    #18535
    Philip
    Participant

    Thanks Tom, that worked and I could go forward with that.

    However, what I was really hoping to do with the wp_show_posts shortcode was use the Lists more like templates. So I could have 2 Lists (with no taxonomy specified in the dashboard) and then use those over and over, wherever I want in various pages, specifying the categories and tags wherever I use them through the settings. So the templates are always the same and the data is different. I don’t think the function you provided above would allow me to do that, since the category and tag are tied to the List ID. Using that, I think I’d need to create dozens of copies of those same Lists and then dozens of copies of that function to match.

    Any clever way you know of to accomplish what I want? Maybe something else I can add to that if statement? Basically just some way I can differentiate each instance of the List, so that I can assign a different category/tag combination to each.

    Thank you.

    #18558
    Tom
    Keymaster

    Hmm, you could give the list a custom class, then do this:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 'my-custom-class' === $settings['wrapper_class'] ) {
            $args['category__and'] = 8;
            $args['tag__in] = 68;
        }
    
        return $args;
    }, 10, 2 );

    That way the filter will apply to all lists with that class.

    Or are you wanting to change the 8 and 68 dynamically?

    #18573
    Philip
    Participant

    That approach could work, but I’d need to be able to set the class via the shortcode in the editor, and whenever I try to do that, I get a fatal error when I try to save, and then have to go remove that code from the database to fix it. This was my shortcode:

    [wp_show_posts id="119" settings="wrapper_class=tag1-cat1"]

    I kept playing with and found a clunky workaround, using a field that I’m not otherwise using:

    [wp_show_posts id="119" settings="read_more_text=tag1-cat1"]

    I’d have to then hide that Read More button with CSS, but its doable. I can then do this:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 'tag1-cat1' === $settings['read_more_text'] ) {
            $args['category__and'] = 8;
            $args['tag__in'] = 68;
        } elseif ( 'tag1-cat2' === $settings['read_more_text'] ) {
            $args['category__and'] = 8;
            $args['tag__in'] = 25;
        } elseif ( 'tag2-cat1' === $settings['read_more_text'] ) {
            $args['category__and'] = 10;
            $args['tag__in'] = 28;
        }
        // etc.
    
        return $args;
    }, 10, 2 );

    Again, very clunky, but at least this gets me to a place where I don’t need to create dozens of Lists. Any better way you know of to do this now that you can see what I’m trying to accomplish?

    #18588
    Tom
    Keymaster

    So why do that instead of reference the list_id, exactly? Will there be that many lists?

    #18596
    Philip
    Participant

    Yes I’ll be using each List format in maybe 20-30 places (multiple times on the homepage plus multiple on every category page).

    It’s not a huge amount up front but if I ever want to make changes across all lists, I’ll have to do it to each and every one. For example if I want them all to change to card style or show 4 posts instead of 3, etc.

    Seems like it makes more sense just to share 2 listS (one for each format I need).

    Or maybe I’m trying to make this plugin do something it’s not meant for and I should use a different one. I’m just using GP so though I’d stay in this ecosystem.

    #18625
    Tom
    Keymaster

    And what will the main difference be between each list?

    Let’s say you have 10 lists, how would they be different?

    Just trying to get an idea of the overall system you’re using so I can see if there’s a smarter way to go about it.

    #18633
    Philip
    Participant

    The main difference is just the category and tags to pull from.

    So I’d have a bunch of lists that are identical other than the category and tags. Then I’d have a bunch more that are almost the same as the first set but a different format (for example card instead of row) and would pull from other categories and tags.

    No two lists would pull from the same category and tag.

    So in the situation above we’d ideally have two Lists (one for each format) as opposed to 20 or more.

    #18654
    Philip
    Participant

    Any further thoughts on this one, Tom? If not, I’ll just go forward with my clunky approach.

    Thanks!

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