WooCommerce search products between price range using WP_Query

The solution: $query = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘product’, ‘posts_per_page’ => 10, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array(50, 100), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ), ), ); $wpquery = WP_Query($query); // return 10 products within the price range 50 – 100

Split wordpress loop to multiple layouts

Just create 2 queries using the “offset” parameter and separate them by: <?php wp_reset_query(); ?> Display posts from the 4th one (offset is starting from 0): <?php $query = new WP_Query( ‘offset=3′ ) ); ?> EDIT: Here’s some sample code: <?php query_posts(‘offset=0&showposts=2&order=ASC’); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <p><a href=”https://wordpress.stackexchange.com/questions/61605/<?php the_permalink(); ?>”><?php the_title(); … Read more

WordPress SQL injection

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, … Read more

Exclude categories from the_category();

Try using the filter get_the_categories and replace every occurrence of the_category by echo get_the_category() (just to be sure !) This is what I cooked: <?php add_filter(‘get_the_categories’, ‘exc_cat’); function exc_cat($cats) { //not on admin pages if(!is_admin()){ $exc = array(‘lipsum’, ‘dolor’); foreach ($cats as $i=>$cat){ if(in_array($cat->name, $exc)){ unset($cats[$i]); } } } return $cats; } ?> Try my … Read more

Save title as custom field on custom post type

This will automatically update a meta named post_title to the value of the post’s title, no matter where you save the post from: function wpse_275785_save_title_as_meta( $post_id, $post, $update ) { update_post_meta( $post_id, ‘post_title’, $post->post_title ); } add_action( ‘save_post’, ‘wpse_275785_save_title_as_meta’, 99, 3 );