Order by custom field date?

There are similar posts on this site about the same topic, if you look around. But here is your answer: To make this work you need to change your date format. You can sort alphabetically, or numerically, not calender-merically. The only human date format that orders correctly is YYYY/MM/DD. The separator are optional and shouldn’t … Read more

searching in custom meta field

After thinking about the problem, I found the simplest solution, do a direct query using $wpdb in archive-{post-type}.php <?php global $wpdb; $meta_key = get_query_var(‘publisher’); $result = $wpdb->get_results(” SELECT * FROM ” . $wpdb->prefix. “postmeta_books WHERE publisher LIKE ‘%$meta_key%’ “); foreach( $result as $results ) { echo $results->publisher; echo ‘<br/>’; } ?> It is the basic … Read more

Is there a way to do multiple ordering on a multiple meta_query?

As of WordPress 3.4.1, there is no way, out of the box, to order by multiple meta values. Since we can’t do it cleanly, we’ll have to hack something together. We can hook into posts_orderby to manually modify the ordering. It’s not altogether pretty, but it will get the job done. Here’s an example: add_filter(‘posts_orderby’, … Read more

Order Posts by Closest Numeric Values

One possibility is a direct SQL query similar to the one given here. But I’m not convinced that it would be much more efficient than 2 queries, all handled by WordPress: The is untested $price =0; //Price of current property $id=0; //Property (post) ID. $args = array( ‘post_type’ => ‘property’, ‘post__not_in’=>array($id), ‘posts_per_page’=> 2, ‘meta_query’ => … Read more

How to delete custom field “suggestions” from dropdown list

You can filter the query for these keys on’query’. I would start that filter as late as possible to avoid side effect. Sample code, tested: add_filter( ‘postmeta_form_limit’, ‘wpse_73543_hide_meta_start’ ); function wpse_73543_hide_meta_start( $num ) { add_filter( ‘query’, ‘wpse_73543_hide_meta_filter’ ); return $num; } function wpse_73543_hide_meta_filter( $query ) { // Protect further queries. remove_filter( current_filter(), __FUNCTION__ ); $forbidden … Read more

Query meta field using between

Your problem is this: CAST(wp_postmeta.meta_value AS SIGNED) Run a simple SQL query (command line or PhpMyAdmin, whatever you like) like SELECT CAST(‘1.2’ as SIGNED) and you will see that the value returned is 1. What causes that cast is ‘type’ => ‘NUMERIC’,. You can pass DECIMAL to meta_query instead of NUMERIC but I don’t see … Read more

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