• Resolved andyss2k

    (@andyss2k)


    Hi, thanks for the great plugin! Is it possible to filter the results received from a Custom Post Type by a post field/meta value? For example, I have a CPT of Providers and a checkbox field of whether they offer a certain service. Can I filter the query to only show those posts with the field checked in the carousel? I would take a guess that I would have to alter the WP_query args to include meta key and meta value, but not sure where or how to do this. Any help on this?

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author livemesh

    (@livemesh)

    That’s easy to do since the plugin is built out of templates that can be extended in your child theme by copying files from the plugin.

    Pls copy the file

    addons-for-elementor/templates/addons/posts-carousel/loop.php

    file to your

    mytheme/addons-for-elementor/addons/posts-carousel/loop.php

    and then modify line number 16 with reference to WP_Query to suit your needs.

    Plugin Author livemesh

    (@livemesh)

    You can also take a look at the Posts Multislider widget which has more features than the posts carousel. Modifying WP_Query is similar to the one described above for the Posts Carousel.

    Thread Starter andyss2k

    (@andyss2k)

    Thanks for the help. I’d like to keep using the Posts Carousel because I am using custom Elementor templates with it. But can you give me a quick and dirty example of modifying line 16?

    Thanks.

    Plugin Author livemesh

    (@livemesh)

    Some examples of how this works –

    If you want to modify the query args –

    $query_args['ignore_sticky_posts'] = 0; // do not ignore sticky posts
    $query_args['orderby'] = 'rand'; // sort random
    
        if (is_front_page()) {
            $query_args['post__not_in'] = array(35139, 35069, 35037); //exclude these posts
        }

    or if you want to replace completely the query args with your own –

     global $post;
    
        $query_args = array(
            'post_type' => 'page',
            'posts_per_page' => -1,
            'post_parent' => $post->ID,
            'order' => 'ASC',
            'orderby' => 'menu_order'
        );

    You can modify the query arguments as per your requirement. Pretty flexible that way.

    Plugin Author livemesh

    (@livemesh)

    You can find several examples of meta key value queries similar to the ones posts above here –

    https://rudrastyh.com/wordpress/meta_query.html

    Thread Starter andyss2k

    (@andyss2k)

    Thanks, that really helps. I just wanted to make sure I wasn’t messing anything up, lol.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Post Carousel Custom Query’ is closed to new replies.