Custom Fields
Re-Envisioned
Support MB Views Integration with Search & Filter Pro

  • Creator
    Topic
  • #27520
    Resolved Clay
    Participant

    Hey guys,

    I'm trying to filter a view using the Search & Filter Pro plugin. It seems like this should be possible but I can't seem to get it to work.

    This is their instruction for filtering custom result:https://searchandfilter.com/documentation/search-results/custom/

    Could you point me in the right direction for doing this?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #27584
    Long Nguyen
    Moderator

    Hi Clay,

    To use a third-party plugin in View, you can create your own function then call it via the proxy mb.function_name(). Get more details on the documentation https://docs.metabox.io/extensions/mb-views/#running-php-functions

    #27629
    Clay
    Participant

    Hey Long,

    I've tried that but can't get it to work. Would you mind including some sample code?

    $args = array('post_type' => 'post');
    $args['search_filter_id'] = 123;
    $query = new WP_Query($args);

    That is the code given by Search & Replace Pro to implement in a custom way.

    Any help would be greatly appreciated.

    #27647
    Long Nguyen
    Moderator

    Hi,

    I have not used the Search & Filter before but if you want to show the results in View, you can create a custom function in the file functions.php or Code Snippets

    function show_my_posts() {
        $args = array('post_type' => 'post');
        $args['search_filter_id'] = 123;
        $query = new WP_Query( $args );
        while ( $query->have_posts() ) {
            $query->the_post();
            echo get_the_title() . '<br>';
        }
        wp_reset_postdata();
    }

    then call it in View via proxy {{ mb.show_my_posts() }}

    #27663
    Clay
    Participant

    Amazing! This got me mostly there. Thanks for the code sample. Is it possible to echo the contents of the Meta Box View in that function so the results being returned and filtered are rendered by the view or would this be done with PHP in the function above?

    #27702
    Long Nguyen
    Moderator

    Hi,

    In the PHP code, you can use the function do_shortcode() to render the shortcode.

    echo do_shortcode('[ mbv id="12345" ]');

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