Tag Info

Hot answers tagged

2

You could try the REGEXP version: 'meta_query' => array( array( 'key' => 'email_address', 'value' => '^hello@', 'compare' => 'REGEXP', ) ) where ^ matches the beginning of a string. You can check the MYSQL reference on REGEXP here for more info. Notice that these are ...


1

Assuming your products are custom posts you can do it like this: add_action('wp_insert_post', 'do_stuff'); // when product is created add_action('save_post', 'do_stuff' ); // on product update function do_stuff( $post_id ) { // Making sure this runs only for products $slug = 'product_post'; if ( $slug != $_POST['post_type'] ) { ...


1

add_filter('posts_orderby', 'posts_orderby'); function posts_orderby($orderby_for_query) { global $wpdb; $prefix = $wpdb->prefix; $orderby_for_query = "LEFT(" . $prefix . "posts.post_date, 10) DESC, " . $orderby_for_query; return $orderby_for_query; } This produces this query: SELECT wp_posts.* FROM ...


1

I think you forgot to check if $the_query have posts. <?php $args = array( 'post_type' => 'testimonials', 'posts_per_page' => 1, 'orderby' => 'rand' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ...



Only top voted, non community-wiki answers of a minimum length are eligible