Search Results: Differentiate posts and pages

<?php if(get_post_type() == ‘page’): // Only pages ?> <div class=”recent_postMetaSingle”> <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/eye.png” alt=”Views” title=”views” /> <?php print_page_views(get_the_ID(”)); ?> <p>This is a static page!</p></div> <?php elseif(get_post_type() == ‘post’): // If not page, Only posts ?> <div class=”recent_postMetaSingle”> <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/eye.png” alt=”Views” title=”views” /> <?php print_page_views(get_the_ID(”)); ?> &nbsp;&nbsp;&nbsp; <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/comments2.png” alt=”Comments” title=”comments” … Read more

Change query variable for wordpress search

The code you found works not by changing the query variable but by converting another variable into the s variable that WordPress expects. If you look at the WP_Query object, that s parameter is pretty deeply embedded into Core functionality. The simple solution, and perhaps the only one, is to choose some other parameter for … Read more

Advanced Search by minimum/maximum values

A meta_query is an array of arrays. You only have an array. $query->set(‘meta_query’, array( ‘key’ => ‘shru_price’, ‘value’ => $_GET[‘minPrice’], ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ )); It should be: $query->set( ‘meta_query’, array( array( ‘key’ => ‘shru_price’, ‘value’ => $_GET[‘minPrice’], ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ) ) ); And please validate/sanitize that user supplied … Read more

Comparing between a negative and positive number

I tried the following code: $posts = get_posts([ “post_type” => “CUSTOM_POST_TYPE”, “meta_query” => [ ‘relation’ => ‘AND’, [ ‘key’ => ‘longitude’, ‘value’ => [-0.9895, 1.3125], ‘compare’ => ‘BETWEEN’, “type” => “NUMERIC”, ], ], ]); When I remove “type” => “NUMERIC”, I could reproduced your problem because the comparison is string based. But when adding the … Read more

Change loop.php for empty search customization

I feel bad for answering my own question on here, but here’s what I did. I created a custom search template, a custom searchform.php and changed my header.php to reflect my custom search page. What I did is rename the search box names to search instead of s to get around WordPress automatically running search.php … Read more

Search result by range?

If you save the the price in a meta field, you can query posts using meta_query: <?php $the_posts = new WP_Query( array( ‘meta_key’ => ‘price’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘price’, ‘value’ => ‘100’, ‘type’ => ‘NUMERIC’, ‘compare’ => ‘>=’ ) ) )); ?> <?php while ( $the_posts->have_posts() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)