how to filter the data's comparison operators (>= & <=) & range between values using the WP REST API

I'm quit new for wordpress development. Working with property management website with mobile API Development. Here need to filter the data's for based on conditions like greater than and less than &amp; between range. For example need to filter and search the data's where price filter range and between and greater or less than bedrooms. Kindly help me to solve this issue.I've tried below example but not works to me http://192.168.0.88:8825/wp-json/wp/v2/properties?filter[meta_key]=property_bathrooms&amp;filter[meta_value]=4&amp;filter[meta_compare]=&gt;=&amp;filter[meta_key]=property_bedrooms&amp;filter[meta_value]=5&amp;filter[meta_compare]=&gt;=&amp;filter[meta_key]=property_price&amp;filter[meta_value]=5,500&amp;filter[meta_compare]=between
Category: Web

3 posts from each existing category on one page

The following is not working... &lt;?php $categories = get_categories( array( 'orderby' =&gt; 'name', 'parent' =&gt; 0 ) ); foreach($categories as $category): $args = array( 'cat' =&gt; $category-&gt;name, 'posts_per_page' =&gt; 3,); $category_posts = new WP_Query( $args ); if( $category_posts-&gt;have_posts() ): ?&gt; &lt;h2&gt;&lt;?php echo $category-&gt;name; ?&gt;&lt;/h2&gt; &lt;div class=&quot;row&quot;&gt; &lt;?php while( $category_posts-&gt;have_posts() ): $category_posts-&gt;the_post(); ?&gt; &lt;div class=&quot;blog-post-tile&quot; style=&quot;background-image: url(&lt;?php echo get_the_post_thumbnail_url(get_the_ID(), 'full');?&gt;)&quot;&gt; &lt;h3 class=&quot;blog-post-tile__title&quot;&gt; &lt;?php the_title(); ?&gt; &lt;/h3&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;?php endif; wp_reset_postdata(); wp_reset_query(); endforeach; My goal is to display …
Category: Web

Numeric pagination custom post type

i create a custom page to display loop of cpt with custom field. I need to add a numberic pagination and i try with this code but not work. Functions.php function pagination_bar() { global $wp_query; $total_pages = $wp_query-&gt;max_num_pages; if ($total_pages &gt; 1){ $current_page = max(1, get_query_var('paged')); echo paginate_links(array( 'base' =&gt; get_pagenum_link(1) . '%_%', 'format' =&gt; '/page/%#%', 'current' =&gt; $current_page, 'total' =&gt; $total_pages, )); } } custompage.php &lt;!--Loop Salmi--&gt; &lt;?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) …
Category: Web

wp_reset_postdata not working

i have this query add_action('edit_form_after_title', 'get_books'); function get_books($main_post){ global $post; $list = ''; // print the current post (everything is still fine here) print_r($post); $args = array( 'posts_per_page' =&gt; '20', 'post_type' =&gt; array('books') ); $my_query = new WP_Query($args); if ($my_query-&gt;have_posts()) { $list .= '&lt;select name="books_list"&gt;'; while ($my_query-&gt;have_posts()) { $my_query-&gt;the_post(); // my code $list .= '&lt;option value="'.get_the_ID().'"&gt;'.get_the_title().'&lt;/option&gt;'; } $list .= '&lt;/select&gt;'; wp_reset_postdata(); } // i try another methods but still same problem. wp_reset_postdata(); $my_query-&gt;reset_postdata(); wp_reset_query(); // here print the last post …
Category: Web

wp_reset_postdata() or wp_reset_query() after a custom loop?

Reading some stuff about query_reset_postdata and query_reset_query makes me confused. For example: Is there any need to use both wp_reset_postdata and wp_reset_query together? http://www.poststat.us/properly-reset-wordpress-query/ Above states that you should only use query_reset_postdata() when using &quot;separate queries&quot;. In example2 there's a comment: WP_Query( $args ) = wp_reset_postdata(); AND query_posts ( $args ) = wp_reset_query(); And really you should never use wp_reset_query because you shouldn't use query_posts!? In the WP Codex it states that you should use wp_reset_query() after a custom loop …
Category: Web

Reset postdata to custom query in nested queries

I have a main query, in which I set up a new custom query to retrieve posts (think about 'related posts' or something like that). Than in each of those posts, I'm setting an other custom query, load data from a single post, then I should find a way to reset postdata to the first custom query. How can I do that? I tried wp_reset_postdata(), but that resets to main query. A simplified code would look thus: while ( have_posts() …
Category: Web

Why does the theme insert the comments section if I don't reset my custom WP_Query?

I have a bit of an odd situation. I have somehow solved it, but I'm trying to understand why my solution works. I'm using TheBuilt, a theme that uses Visual Composer. I have extended Visual Composer with a custom element that I use to display a custom posts page (the main loop is not in use on that page, nor is any other custom loop). In order to build a posts object, I create a new WP_Query object that looks …
Category: Web

3 Posts in Loop, Show Stickies First

Okay I am starting to wonder if it is even possible to do this! As I've found very little info on the matter online. This is a fresh WP install that I've been experimenting on so that I can work in a more simplified environment (rather than try to solve the full problem itself on my live client's website if that makes sense). I'm trying to display a total of 3 posts using query_posts(). I want the sticky posts to …
Category: Web

Populate metabox dropdown with post title from another Custom Post Type (issues with wp_reset / global $post)

I have a custom post type, and in there I have a metabox with a dropdown. The dropdown is populated with the titles of posts from another custom post type. My metabox system works. I tried hardcoding the options and they save correctly. I can also pull the data from the custom post type to populate the dropdown. The issue lies within the save/loading of data. I've tried wp_query and get_posts, with their corresponding resets, but whenever I try to …
Category: Web

wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query

I'm implementing a form for a frontend post with a shortcode. The form is processed in the same function, reloading the page: function adicionar_ninhada(){ $user_id = get_current_user_id(); if (isset($_POST['adicionar_cachorro'])){ wp_verify_nonce( $_POST['_wpnonce'], 'brg_add_dog'.$user_id ); $args = array( 'post_title' =&gt; $_POST['raca'] . " nascidos em " . $_POST['nascimento'] , 'post_content' =&gt; '', 'post_status' =&gt; 'publish', 'post_author' =&gt; $user_id, 'post_type' =&gt; 'ninhada', ); $post_id = wp_insert_post( $args ); if(isset($_FILES['foto_upload'])){ require_once( ABSPATH . 'wp-admin/includes/image.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/media.php' …
Category: Web

WP_Query in functions.php overrides global $post object, even with wp_reset_query()

I've written a function that grabs all posts that are drafts and puts them as a dropdown in my toolbar for easy access to complete. This works just fine. The problem is that it seems to mess with my global $post object, specifically when called in my post/page editor. So if I'm in my post editor: http://example.com/wp-admin/post.php?post=147&amp;action=edit 147 is the post I want to edit. But instead of showing the post corresponding to 147, it's showing the last draft in …
Category: Web

2 queries with counters

I have 2 loops on a page both containing a counter to implement slightly different code every 6 posts. For some reason though the second loop is implementing the different code sometimes after 4 items instead of 6. Am I not resetting the loop correctly? &lt;ul class="tabs"&gt; &lt;li class="tab-link current" data-tab="tab-1"&gt;Most Popular&lt;/li&gt; &lt;li class="tab-link" data-tab="tab-2"&gt;Recent&lt;/li&gt; &lt;/ul&gt; &lt;div id="tab-1" class="tab-content current"&gt; &lt;div class="slider"&gt; &lt;div class="slide"&gt; &lt;?php query_posts('meta_key=post_views_count&amp;orderby=meta_value_num&amp;order=DESC&amp;post_type=atls_video&amp;posts_per_page=-1'); if (have_posts()) : while (have_posts()) : the_post();$count++; ?&gt; &lt;?php if ($count%6== 0) : ?&gt; …
Category: Web

How to do a loop inside a loop?

I'm trying to get posts from a custom posts using WP_Query. &lt;ul&gt; &lt;?php $query1 = query_posts( array( 'posts_per_page' =&gt; -1, 'post_type' =&gt; array('specialties') )); if(have_posts()): while(have_posts()): the_post(); ?&gt; &lt;li&gt; &lt;!-- title from post type specialties --&gt; &lt;p&gt;&lt;?php the_title(); ?&gt;&lt;/p&gt; &lt;/li&gt; &lt;?php endwhile; endif; wp_reset_query(); ?&gt; &lt;/ul&gt; It's working just fine. Now I need to get posts from another custom post and show inside the already created loop. Now the code looks like this: &lt;ul&gt; &lt;?php $query1 = query_posts( array( 'posts_per_page' …
Category: Web

Different number of posts showing in development vs production server

So I'm working on a website for a client. Everything works fine except for the fact that the number of posts showing in the homepage of my development server is different from the number of posts showing in the production server. Here's my query: &lt;?php $args = array( 'post_type' =&gt; 'post', 'posts_per_page' =&gt; 4 ); $loop = new WP_Query( $args ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;div class="mini-post col-xs-12 col-md-6 col-lg-6"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt; &lt;h3&gt;&lt;?php $title = …
Category: Web

Related post by category throws internal server error

I am using thesis in wordpress 4.1 i am trying to display related post by category with bellow function but when i go to the post detail page it throws internal server error.i have used same code in another website and the code is working good on that site and each word of code is same on both site i am stucked here i was increased the wordpress memory limit ,in php.ini file memory limit but that also not taking …
Category: Web

WP_Query and is_page_template() conditional

I have a custom query that goes looks like this: $temp = $wp_query; $wp_query = null; $args = array('posts_per_page' =&gt; 5, 'post_type' =&gt; 'gallery', 'post_status' =&gt; 'published', 'paged' =&gt; $paged); $wp_query = new WP_Query($args); if($wp_query-&gt;have_posts()): while($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); if(get_post_format()) { $post_format = get_post_format(); } else { $post_format = 'standard'; } get_template_part('/templates/parts/format', $post_format); endwhile; endif; ?&gt; Inside post format that I call with get_template_part('/templates/parts/format', $post_format); I have conditional is_page_template(). This conditional isn't working. But when I use regular WP_Query without resetting …
Category: Web

Resetting a Query using wp_reset_query() or wp_reset_postdata() does not work

I am using ACF as related posts. I have the following code. &lt;?php $post_objects = get_field('repeater_related_items'); if( $post_objects ): ?&gt; &lt;ul&gt; &lt;?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?&gt; &lt;?php setup_postdata($post); ?&gt; &lt;li&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;span&gt;&lt;?php the_field('repeater_related_items'); ?&gt;&lt;/span&gt; &lt;/li&gt; &lt;?php endforeach;?&gt; &lt;/ul&gt; &lt;?php wp_reset_postdata(); ?&gt; &lt;?php endif;?&gt; &lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Main Sidebar') ) : endif; ?&gt; The problem is that when I add this to sidebar other widget doesn't …
Category: Web

Problem with different query loops (and "main loop") on category template page!

so, heres the problem: i've created a category-template (category.php) with two query loops and the main loop (in which the content from the category should get looped in). if i now click on a category the template page shows but also the first two query loops get affected by it. everything is messed up. above is my template architecture. as you can see, i used the wp_reset_query function but this did not help. how do i make JUST THE MAIN …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.