• I have a page called athletes.

    With a normal loop it’s working:

    while(have_posts()):the_post(); ?>

    But with:

    <?php
    $args = array(
    	'orderby' => 'rand',
    	'nopaging' => 'true',
    	'post_type' => 'athlete',
    	);
    
    $catquery = new WP_Query($args);
    	while($catquery->have_posts()) : $catquery->the_post();
    ?>

    The filters aren’t doing anything.

    How do I fix this?

    Thanks in advance.

    https://ww.wp.xz.cn/plugins/beautiful-taxonomy-filters/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Maveee

    (@maveee)

    Or is it impossible to make the filters work on a WP_Query loop?

    Plugin Author Jonathandejong

    (@jonathandejong)

    Hi maveee,

    The filter is purely for the purpose of filtering an archive loop of a CPT.
    So in short you can’t use it to filter your custom wp_query.

    It’s not that tricky to create your own filtering function on a custom WP_Query tho.
    You can create a form of your own which uses the GET method to let users select taxonomy terms.

    Then you’ll check for any set GET parameters after your $args and if they exist you add to your $args accordingly. Thus your $catquery will be filtered using your GET parameters in the URL. If you need more detailed help than that I suggest you ask in the general forum or on stackoverflow 🙂

    The example you’re providing however seems to be pretty much like a standard archive loop with a few exceptions. Have you considered using the standard loop and query and just modify the query with your parameters using the pre_get_posts filter?

    function hwl_home_pagesize( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
    
        if ( is_post_type_archive( 'athlete' ) ) {
            $query->set( 'posts_per_page', -1 ); //Does the same as nopaging
            $query->set( 'orderby', 'rand' );
            return;
        }
    }
    add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Filters not working on custom loop? (wpquery)’ is closed to new replies.