Forums › Forums › Search & Filter Pro › Help with WP_Query not working
- This topic has 32 replies, 2 voices, and was last updated 7 years, 1 month ago by
Anonymous.
-
Anonymous(Private) March 21, 2018 at 11:08 pm #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(Private) March 22, 2018 at 11:56 am #167600It 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; ?>
Anonymous(Private) March 22, 2018 at 1:07 pm #167644Thanks, 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?
Anonymous(Private) March 22, 2018 at 1:13 pm #167652Notice: 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
-
AuthorPosts