ORDER BY custom field value

You can create groups of meta_queries using specific compare operation on them, and since you want to order based in a single custom field, you can keep the order declaration dedicated to the single meta field. So: $q = new WP_Query( array( ‘meta_key’ => ‘population’, //setting the meta_key which will be used to order ‘orderby’ … Read more

Sortable Custom Columns in User Panel (users.php)?

My first answer was completely off-mark and I’m completely rewriting it… But thanks to Milo’s hint, I found the solution here: http://wordpress.mcdspot.com/2011/05/24/search-admin-user-list-on-first-and-last-names/ After adapting it, this works for me with ‘facebook’ and ‘twitter’ author_meta. add_action(‘pre_user_query’,’wpse_27518_pre_user_query’); function wpse_27518_pre_user_query($user_search) { global $wpdb,$current_screen; if ( ‘users’ != $current_screen->id ) return; $vars = $user_search->query_vars; if(‘facebook’ == $vars[‘orderby’]) { $user_search->query_from … Read more

Query Posts or Get Posts by custom fields, possible?

To query posts by custom fields you can use the ‘meta_query’ parameter <?php $args = array( ‘post_type’ => ‘payment’, ‘meta_query’ => array( array( ‘key’ => ‘bookingref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘customerref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ) ); query_posts($args); while (have_posts()) : the_post(); ?> you can’t use get_post_meta … Read more

Underscores in custom fields

Custom field names are arbitrary. The underscore hides it from the Custom Fields metabox on the post editing page. When referencing these custom fields in meta_query() or other functions, the underscore has to be used. Source: conversation with @toscho, @rarst and @wyck in the chat room.

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