$wpdb query for price in custom field value
You can try the following: AND ($wpdb->postmeta.meta_key = ‘cc_price’ AND $wpdb->postmeta.meta_value LIKE ‘%$s_prc%’) (Use cc_price instead of $cc_price)
You can try the following: AND ($wpdb->postmeta.meta_key = ‘cc_price’ AND $wpdb->postmeta.meta_value LIKE ‘%$s_prc%’) (Use cc_price instead of $cc_price)
Add the below code in your active theme’s functions.php file. function wpse_delete_query_transient( $post ) { // Deletes the transient when a new post is published delete_transient( ‘d_results’ ); } add_action( ‘new_to_publish’, ‘wpse_delete_query_transient’ ); This will delete the transient every time when a new post is published. If you want to delete the transients on differrent … Read more
I am not good at SQL but I believe this SQL query will do the job for you. UPDATE wp_posts SET post_status=”publish” WHERE post_type=”product” AND post_status=”trash”; Please remember to change WP database prefix if it is not default wp.
After Milo’s help I found a function where it altered the search query: if( is_search() && empty($_GET[‘post_type’]) && !is_admin() ) { global $wpdb; $query = get_search_query(); $query = $wpdb->esc_like( $query ); $where .= ” OR {$wpdb->posts}.ID IN (“; $where .= “SELECT {$wpdb->postmeta}.post_id “; $where .= “FROM {$wpdb->posts}, {$wpdb->postmeta} “; $where .= “WHERE {$wpdb->posts}.post_type=”page” “;<-page to … Read more
You can do this by naming index of meta query, then passing array of these names in orderby parameter $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ’10’, ‘meta_query’ => array( ‘relation’ => ‘OR’, ‘with_time’ => array( ‘key’ => ‘TIME_meta_key’, ‘compare’ => ‘EXISTS’ ), ‘without_time’ => array( ‘key’ => ‘TIME_meta_key’, ‘compare’ => … Read more
Use $wpdb->get_results with filter based on array
I noticed that the problem was related that one custom field was a taxonomy, so, as I was using the archive page for that custom post type, I only needed to filter the query looking for the date limits. $fecha_actual = current_time(‘Ymt’); //t regresa el ultimo día del mes $fecha_anterior = date(‘Ymd’, strtotime(“first day of … Read more
Woah there. You’ve just opened up a can of SQL injection. I use the default get_query_var(‘s’) that I believe is automatically escaped by wordpress. Not quite – get_search_query() will do that, but get_query_var( ‘s’ ) gets the “raw” value. Regardless, always use wpdb::prepare or similar escaping before executing SQL: $query = $wpdb->prepare( “SELECT * FROM … Read more
To search for posts based on date, you can set up a quick instance of WP_Query. The best place to look is the official documentation, and in particular the section on the date parameters. A basic search for posts in a particular month will look a little like this: <?php $the_query = new WP_Query( array( … Read more
Performance of wp_get_attachment_image_srcset() and wp_get_attachment_image_url()