meta_value and meta_key filtering returning no posts [closed]
Taxonomies and meta data (Custom Fields) are two different things. If you want to filter on a taxonomy term, you want a tax_query, not a meta query.
Taxonomies and meta data (Custom Fields) are two different things. If you want to filter on a taxonomy term, you want a tax_query, not a meta query.
Separate the allowed values in a function: function get_allowed_values() { return array(‘one’, ‘two’, ‘three’); } In your metabox: foreach ( get_allowed_values() as $item) {} In your validation handler: if ( isset( $_POST[‘select_meta’] ) and in_array( $_POST[‘select_meta’], get_allowed_values() ) )
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
There is a way to put that meta box after the title. There is a hook called edit_form_after_title. If you look at the source there is no hook earlier than that that isn’t much too early– outside of the <form tag. The following does move that box to the location after the title… function generic_box() … Read more
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
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
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
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
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
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