• What can I do to make the file classes/YARPP_Core.php finally there is a filter for $wp_query?

    Honestly — a few characters of code and the ability to change the request on the fly. Also, do not make changes to the plugin files after each update.

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Michael Nelson

    (@mnelson4)

    Hi @malferov, yeah it’s been pretty slow going; it sounds like you had to directly edit the plugin’s files locally and they’re getting overwritten with each update. I’m sorry you’re in that situation, but hopefully, we can get a change in YARPP core soon (like in the next few days or weeks) so your changes won’t get overwritten like that.

    I made a branch that lets you filter the WP_Query YARPP creates, but I tried to reduce duplication, so you could use a filter and have it affect YARPP::get_related, YARPP::display_related and YARPP::related_exists.

    Would you like to give it a try before we release it?

    Here’s a zip of it you can upload to your site: https://github.com/shareaholic/wp-yet-another-related-posts-plugin/archive/MN-54-add-filter.zip

    We have some documentation in the works, but hasn’t been fully published yet. But here’s a screenshot: https://drive.google.com/file/d/16YJBwyUapNIUtasTYN4Y7X6tJXSIIbvQ/view

    One complication with using this filter is caching: YARPP doesn’t use the WP_Query when deciding whether or not to refresh the cache, it only uses the “args” passed into it. So if the query args you’re adding with this filter change, you’ll need to also manually flush YARPP’s cache using global $yarpp; $yarpp->cache->flush();.

    Please let me know what makes sense and what doesn’t, and how well it meets your user-case. (What is your use-case anyway?)

    Thread Starter Mikhail Alferov

    (@malferov)

    Hi!

    ZIP-link is 404, unfortunately.

    Use-case:

    My related post – is a products (goods), not news or notes. I need in Related Products section of Product page see only in-stock goods. But YARPP can show all related products: in stock and out of stock. (YARPP is guided by the principles of related posts, and I also need to see only those related posts (products) that are currently in stock.)

    I need see maximum 6 goods in Related Product section in Product page, but more or less at other place of web-shop’s, or other count of items at other time… without re-cache YARPP (in Settings i have 18 in Max related posts and can change this parameter in my code at any moment).

    /*
        * Filter wp_query of YARPP Plugin
        */
        add_filter('yarpp_display_related_wp_query', 'yarpp_custom_wp_query');
        function yarpp_custom_wp_query($args) {
    	// Show in-stock only
            $meta_query = [
                [
                    'key' => 'sklad_1',
                    'value' => 0,
                    'compare' => '>',
                    'type' => 'numeric',
                ]
            ];
    
            $args = [
                'post_status' => 'publish',
                'order' => $args['order'],
                'orderby' => $args['orderby'],
                'p' => $args['p'],
                'post_type' => $args['post_type'],
                // Set more in Setting in Admin panel
                // so that at least 6 of them (possibly fewer) can be shown
                'showposts' => 6,
                'meta_query' => $meta_query,
            ];
    
            return $args;
    }

    Sorry, but i can’t test code on production ??

    Plugin Support Michael Nelson

    (@mnelson4)

    Ah ok thanks for sharing about your use-case.

    And sorry, that last zip download link actually wasn’t public. Here’s one that is: https://drive.google.com/u/0/uc?id=1TZ6hsHlHPrr2zJ_I2Ww2SRHGbENktDc7&export=download

    Do you have a test site you’d like to try it on before we make this live? I’m pretty sure your code snippet would work, you’d just need to change the name of the filter to yarpp_get_wp_query_args.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The query filter 3 (continued)’ is closed to new replies.