Add Hook for clearing transient when post is added

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

$query->set( ‘post_type’, ‘post’ ); not working

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

Query Posts that have or don’t have a meta_value and order by the same ASC

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

Limiting a filtered query

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

How to make MySQL search queries with quotes

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

YearMonth datequery

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

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