How to include template according to meta post value
Finally got a solution. I was not able to get meta key ie my_key value then I used: $post_id = get_the_ID(); $has_customization = get_post_meta($post_id, ‘my_key’, true);
Finally got a solution. I was not able to get meta key ie my_key value then I used: $post_id = get_the_ID(); $has_customization = get_post_meta($post_id, ‘my_key’, true);
You got the wrong id for your get_post_meta(). As you define the input-name by the id of the field in your metabox, it has to be portfolio_description. <?php echo get_post_meta($post->ID, “portfolio_description”, true); ?> Should do the trick. If you are not sure which name of the post_meta you need to call, try inspecting the input … Read more
First off, there’s a problem with your array. Arrays can not have duplicate keys. So, only the first key will be saved. You need to change your form to something like this. <input name=”mainStageSatOrder[theband0][theid]” type=”hidden” class=”band-id” value=”” />”; <input name=”mainStageSatOrder[theband0][theorder]” type=”hidden” class=”band-order” value=”” />”; <input name=”mainStageSatOrder[theband1][theid]” type=”hidden” class=”band-id” value=”” />”; <input name=”mainStageSatOrder[theband1][theorder]” type=”hidden” class=”band-order” value=”” … Read more
Rick James and I have created the (free, GPL) Index WP MySQL for Speed plugin. It addresses some of the performance problems with wp_postmeta by adding database indexes suitable for that table’s use cases. I use it myself on a Woo site with several thousand products. (It works on users, terms, options, and comments too.) … Read more
You can use this filter to change order : $type = “cptCode”; add_filter(“rest_” . $type . “_query”, function ($args, $query) { $args[“orderby”] = “meta_value”; $args[“meta_key”] = “my_meta_field”; return $args; }, 10, 2); You can also test $_GET to change the order conditionally.
You can create a filter using the “wp_get_attachment_image_attributes” hook. Place this in your functions.php file. function filter_image_title($attr, $attachment = null){ //Find your $photographer with $attachment->ID $attr[‘title’] .= ‘ (‘ . __(‘Photographed by’, ‘foobar’) . ‘ ‘ . $photographer . ‘)’; return $attr; } add_filter(‘wp_get_attachment_image_attributes’, ‘filter_image_title’, 10, 2);
Try the following… global $wpdb; $wpdb->query( ” UPDATE {$wpdb->prefix}postmeta SET post_id = {$edit_id}, meta_key = ‘{$meta_key}’, meta_value=”{$meta_value}” WHERE post_id = {$edit_id} AND meta_key = ‘{$meta_key}’ ” ); //or using prepare $wpdb->query( $wpdb->prepare( ” UPDATE {$wpdb->prefix}postmeta SET post_id = %d, meta_key = %s, meta_value = %s WHERE post_id = %d AND meta_key = %s “, $edit_id, … Read more
Add an array and choose one for the value. add_action(‘draft_post’, ‘add_custom_field’); function add_custom_field($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { $colors = array(‘white’, ‘green’, ‘blue’); add_post_meta($post_ID, ‘random_color’, $colors[array_rand($colors, 1)], true); } }
Try this: add_filter(‘posts_where’, ‘unquote_numeric_meta_value’, 10, 2); function unquote_numeric_meta_value($where, $args) { $value = isset($args->query_vars[‘meta_value’]) ? $args->query_vars[‘meta_value’] : false; if(is_numeric($value)) $where = str_replace(“‘{$value}'”, $value, $where); return $where; }
// function to show a banner using query of banner post type function show_banner( $att ) { // Set default $att values if none is provided // $att is an array so access the shortcode value via $att[‘thumbnail_id’] // in the [banner thumbnail_id=”12″] shortcode $atts = shortcode_atts( array( ‘thumbnail_id’ => ”, ), $atts, ‘banner’ ); … Read more