Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months

First of all I don’t think you should use your custom query_posts in here. WordPress already queries posts on archive pages, so it’s waste of time to query them one more time. You should be using pre_get_posts filter. function my_pre_get_posts($query) { if (!is_admin() && is_main_query() ‘<YOUR_POST_TYPE>’ === $query->query_vars(‘post_type’) && $query->is_archive()) { $query->set(‘orderby’,’meta_value’); $query->set(‘meta_key’, ‘<YOUR_POST_TYPE>’); //formatted … Read more

Custom metabox not displaying multiselect data in edit mode

I tested your code and this ended up working for me: case ‘multiselect’: echo ‘<select name=”‘.$field[‘id’].'” id=”‘.$field[‘id’].'”>’; foreach ($field[‘options’] as $option) { echo ‘<option’, $meta == $option[‘value’] ? ‘ selected=”selected”‘ : ”, ‘ value=”‘.$option[‘value’].'”>’.$option[‘label’].'</option>’; } echo ‘</select><br /><span class=”description”>’.$field[‘desc’].'</span>’; break; For the Field Array I just added another option with a blank value and a … Read more

modify wordpress custom field value – strip character if exists

You might try this: <?php $str=”This is a very large number 999,999,999.999 !”; echo $str = preg_replace( ‘/[^\d,.]/’, ”, $str ); to only allow: digits (0-9) commas (,) dots (.) You might then consider filters like: add_{$meta_type}_metadata update_{$meta_type}_metadata get_{$meta_type}_metadata where $meta_type is the type of object metadata (comment, post or user). ps: just remember to … Read more

Display custom field & value correctly on page

You can use <?php the_meta(); ?> to do this (id you want to print them inside the Loop). From Codex: This is a simple built-in function for displaying custom fields for the current post, known as the “post-meta” (stored in the wp_postmeta table). It formats the data into an unordered list (see output below). It … Read more

Displaying Custom Field Array

echo get_post_meta($postid,’meta_key_name’,true); is what you want if the plugin is storing data as individual keys in the post meta table. You may be dealing with an array of values though which would require something like: $meta_data = get_post_meta($postid,’meta_key_name’); // var_dump($meta_data); // debugging echo $meta_data[‘some_key’]; echo $meta_data[‘another_key’]; As you don’t even name the plugin or provide … Read more

Sortable custom field values from all posts on a page template

What if you use ORDER BY pm.meta_value ASC in WP db class: $r = $wpdb->get_col( $wpdb->prepare( ” SELECT pm.meta_value FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE pm.meta_key = ‘%s’ AND p.post_status=”%s” AND p.post_type=”%s” ORDER BY pm.meta_value ASC “, $key, $status, $type ) ); That will provide you an ASCending ordered … Read more

Link the retrieved custom field values to its respective posts

You achieve this by modifying your code as following and using get_results function instead of get_col function. <?php function get_meta_values( $key = ”, $type=”post”, $status=”publish” ) { global $wpdb; if( empty( $key ) ) return; $r = $wpdb->get_results( $wpdb->prepare( ” SELECT pm.meta_value, p.ID FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE … Read more