How to get post meta value and post in one query?

When you do a query WordPress already gets the post_meta. Even though you are calling get_post_meta() It is not performing another query. It is retrieving the value from the post meta cache. Now if you don’t need the post meta you can set a flag that will eliminate the additional MySql query. To do this … Read more

tax_query in WP_Query problem

Thanks to Rarst for pointing me in the right direction. After a bit of playing around the following query is now producing the effect I’m after: $query_args = array( ‘numberposts’ => $limit, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘post_type’ => ‘match’, ); $query_args[‘meta_query’] = array( ‘key’ => ‘played’, ‘value’ => true, ); if ( isset( … Read more

Query Posts but only return 1 from a custom taxonomy?

I think that using standard WP_Query you should run 6 different loops, but this is overwhelming. But using a custom $wpdb query you can do the trick… function get_unique_posts_tax( $taxonomy = ‘category’, $number = 10, $cpt=”post”) { global $wpdb; return $wpdb->get_results( $wpdb->prepare( “SELECT p.* FROM $wpdb->term_relationships JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id JOIN … Read more

wp_delete_post deletes all posts instead of just expired ones

In case anyone else needs the code, this is how I solved it. @pieter-goosen was right, I did need to query the correct posts, but the real trick was matching the date format from the jquery datepicker when running the post query. Check the date formats below, jquery is ‘yy-mm-dd’, and the php equivalent is … Read more

This AJAX Code Doesn’t Work – Looking for elegant solution

Working Code Based On My Previous Answer Without using nonce.. but you can check the previous answer on how you can implement a nonce check. And the code is based on your code. misha_my_load_more_scripts() in functions.php function misha_my_load_more_scripts() { wp_register_script( ‘my_loadmore’, get_stylesheet_directory_uri() . ‘/js/myloadmore.js’, array( ‘jquery’ ), ”, true ); wp_enqueue_script( ‘my_loadmore’ ); } add_action( … Read more

Shortcode returns escaped HTML tags

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens. // WP Shortcode function text_shortcode() { return ‘<strong>bold text:</strong> <a href=”https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags”>See wordpress.stackexchange.com</a>’; } add_shortcode(‘bold-text’, ‘text_shortcode’); Your WordPress shortcode would be: [bold-text] Edit: You don’t need html_entity_decode or htmlentities only when you’re doing something … Read more

How to order a post type with meta_value_num and if meta_value_num does not exist then order by date

You can pass a space-delimited set of columns to orderby argument of WP Query: $args = array( ‘meta_key’ => ‘wp_ratings’, ‘orderby’ => ‘meta_value_num date’ ); $query = new WP_Query( $args ); You can also pass an array of key => sort_order for more granular control, for example: $args = array( ‘meta_key’ => ‘wp_ratings’, ‘orderby’ => … Read more

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