Support Forums

Hey there, it looks like you've been redirected from designsandcode.com - as you can see we have a new home - read more

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Help with WP_Query not working

Viewing 10 posts - 1 through 10 (of 33 total)
  • Thomas
    #167508

    Hi there,

    I trying your WP_query method in a custom page template to display the filters for one of my custom post types. The query works fine (I get the list of posts) but as soon as I pass in the relevant Search Filter Pro ID, everything breaks (I the not working message I set below).

    This is the code I’m using:

    <?php
    $args = array(
      'post_type'   => 'testi',
     );
    $args['search_filter_id'] = 2030;
    $testimonials = new WP_Query( $args );
    if( $testimonials->have_posts() ) :
    ?>
      <ul>
        <?php
          while( $testimonials->have_posts() ) :
            $testimonials->the_post();
            ?>
              <li><?php the_title();  ?></li>
            <?php
          endwhile;
          wp_reset_postdata();
        ?>
      </ul>
    <?php
    else :
      esc_html_e( 'Not working', 'text-domain' );
    endif;
    ?>

    Could you know what I’m doing wrong?

    Thanks!

    Trevor Moderator
    #167600

    It might be the comma at the end of line 3, after 'testi

    Try this maybe:

    <?php
    $args = array(
      'post_type'   => 'testi',
      'search_filter_id' => 2030
     );
    $testimonials = new WP_Query( $args );
    if( $testimonials->have_posts() ) :
    ?>
      <ul>
        <?php
          while( $testimonials->have_posts() ) :
            $testimonials->the_post();
            ?>
              <li><?php the_title();  ?></li>
            <?php
          endwhile;
          wp_reset_postdata();
        ?>
      </ul>
    <?php
    else :
      esc_html_e( 'Not working', 'text-domain' );
    endif;
    ?>
    Thomas
    #167644

    Thanks, I didn’t see that I added that comma while trying to solve this.

    However this wasn’t the problem, I’m still getting the same error 🙁

    I don’t need to do anything else than adding this line on my template and the URL in the search from admin form, right?

    Trevor Moderator
    #167646

    That is correct. What error is it you are seeing?

    Thomas
    #167648

    Just a sec, I’ll enable WP_debug

    Thomas
    #167652

    Notice: is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /home/nsquareeu/public_html/voxscientia.eu/wp-includes/functions.php on line 4147

    Trevor Moderator
    #167654
    This reply has been marked as private.
    Thomas
    #167656
    This reply has been marked as private.
    Trevor Moderator
    #167667

    I cannot see anything wrong. Can you try using the shortcode method instead? Using a test page?

    Thomas
    #167679
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 33 total)

You must be logged in to reply to this topic.