Forums Forums Search & Filter Pro Search with WP_Query

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #3643

    Hello!

    How can I create a search template with a custom number of post retrieved, and make it work with Search & Filter Pro?

    I mean, my WP config is to show 5 posts, but in the Search & Filter template I’m using I want to show 80 posts (custom post_type).

    I’m trying do this with WP_Query, but the Ajax filter don’t work.
    I’ve tried without Ajax, and doesn’t works too.

    Here is the loop I’m trying:
    <?php
    /**
    * Loop – Search
    *
    * This is the loop logic used on the search results screen.
    *
    * @package WooFramework
    * @subpackage Template
    */
    global $more; $more = 0;

    woo_loop_before();

    wp_reset_postdata();
    global $post;

    $args = array( ‘post_type’ => ‘materiais_educativos’, ‘posts_per_page’ => 40 );
    $wp_query = new WP_Query($args);

    if ( $wp_query->have_posts()) { $count = 0;

    //$title_before = ‘<h1 class=”archive_header”>’;
    //$title_after = ‘</h1>’;

    //echo $title_before . sprintf( __( ‘Search results for "%s"’, ‘woothemes’ ), get_search_query() ) . $title_after;
    ?>

    <div class=”fix”></div>

    <?php

    while ( $wp_query->have_posts()) { $wp_query->the_post(); $count++;

    if (get_option(‘woo_woo_tumblog_switch’) == ‘true’) { $is_tumblog = woo_tumblog_test(); } else { $is_tumblog = false; }

    woo_get_template_part( ‘content’, ‘search-materiais-educativos’ );

    } // End WHILE Loop

    wp_reset_postdata();

    } else {
    get_template_part( ‘content’, ‘noposts-materiais-educativos’ );
    } // End IF Statement

    woo_loop_after();

    woo_pagenav();
    ?>

    Thanks

    Ross Moderator
    #3675

    Hey Joao

    You should remove “wp_query” you should not create new queries on your template page only use the existing ones.

    Are you using the new Ajax features from the latest update? Maybe this is easier to use 🙂

    Thanks

    Anonymous
    #3699

    Right, thanks Ross.

    Yes, I’m using Ajax.

    I solved this changing the others post’s types queries, then changing the default WordPress number of posts retrieved os archives to a big number.

    Here’s the code I used in functions.php to change the queries for other posts:
    // LIMITAR NUMERO DE POSTS EM ARQUIVOS E BUSCA
    function five_posts_on_homepage( $query ) {
    if ( $query->is_archive() || $query->is_search && $query->is_main_query() ) {
    $query->set( ‘posts_per_page’, 5 );
    }
    }
    add_action( ‘pre_get_posts’, ‘five_posts_on_homepage’ );

    // LIMITAR NUMERO DE POSTS EM ARQUIVOS DE CUSTOM POST TYPES
    function iti_custom_posts_per_page($query)
    {
    switch ( $query->query_vars[‘post_type’] )
    {
    case ‘evento’: // Post Type named ‘iti_cpt_2’
    $query->query_vars[‘posts_per_page’] = 5;
    break;

    default:
    break;
    }
    return $query;
    }

    if( !is_admin() )
    {
    add_filter( ‘pre_get_posts’, ‘iti_custom_posts_per_page’ );
    }

    Regards,
    Joao

    Ross Moderator
    #3730

    Great so everything is working ok now for you?

    Anonymous
    #3775

    Yes! =)

Viewing 5 posts - 1 through 5 (of 5 total)