I’ve created a Customized Submit Sort and added 50+ posts.
Now this publish kind have some meta values which I have to show.
Right here is how I created the publish kind:
perform colorshadescpt() {
register_post_type( 'colorshades',
array(
'labels' => array(
'identify' => __('Colour Shades'),
'singular_name' => __('Shade'),
'add_new_item' => __('Add New'),
'edit_item' => __('Edit'),
'new_item' => __('Add New'),
'view_item' => __('View'),
),
'public' => true,
'helps' => array( 'title'),
'capability_type' => 'publish'
)
);
}
add_action('init', 'colorshadescpt');
And added this meta_boxes:
$prefix = 'cg_';
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'colorcodes',
'title' => 'Colour Code',
'pages' => array('colorshades'),
'fields' => array(
array(
'identify' => 'Colour code', // discipline identify
'desc' => 'Enter Colour code right here.', // discipline description, elective
'id' => 'color_code', // discipline id, i.e. the meta key
'kind' => 'textual content', // textual content field
'std' => '', // default worth, elective
),
)
);
$meta_boxes[] = array(
'id' => 'colorshades',
'title' => 'Colour Worth',
'pages' => array('colorshades'),
'fields' => array(
array(
'identify' => 'R', // discipline identify
'desc' => 'Enter Purple colour worth right here.', // discipline description, elective
'id' => 'red_code', // discipline id, i.e. the meta key
'kind' => 'textual content', // textual content field
'std' => '', // default worth, elective
),
array(
'identify' => 'G', // discipline identify
'desc' => 'Enter inexperienced colour worth right here.', // discipline description, elective
'id' => 'green_code', // discipline id, i.e. the meta key
'kind' => 'textual content', // textual content field
'std' => '', // default worth, elective
),
array(
'identify' => 'B', // discipline identify
'desc' => 'Enter blue colour worth right here.', // discipline description, elective
'id' => 'blue_code', // discipline id, i.e. the meta key
'kind' => 'textual content', // textual content field
'std' => '', // default worth, elective
),
array(
'identify' => 'Sort', // discipline identify
'desc' => 'Please Choose kind for shade.', // discipline description, elective
'id' => 'shade_color_type', // discipline id, i.e. the meta key
'kind' => 'radio', // textual content field
'std' => 'product',
'choices' => array( // array of key => worth pairs for radio choices
'product' => 'Product',
'machine' => 'Machine',
), // default worth, elective
),
)
);
$meta_boxes[] = array(
'id' => 'productid',
'title' => 'Product Settings',
'pages' => array('colorshades'),
'fields' => array(
array(
'identify' => 'Product Id',
'desc' => 'Enter the product id right here.',
'id' => 'colors_product_id',
'kind' => 'textual content',
'std' => '',
),
)
);
$meta_boxes[] = array(
'id' => 'shade_details',
'title' => 'Different Particulars',
'pages' => array('colorshades'),
'fields' => array(
array(
'identify' => 'Particulars', // discipline identify
'desc' => 'Enter shade particulars.', // discipline description, elective
'id' => 'colors_details', // discipline id, i.e. the meta key
'kind' => 'textarea', // textual content field
'std' => '', // default worth, elective
),
)
);
foreach ($meta_boxes as $meta_box) {
$my_box = new RW_Meta_Box_Taxonomy($meta_box);
}
Right here is the screenshot of the way it seems as a publish:
How I get the end result on the opposite facet:
<?php
international $product;
$args = array(
'post_type' => 'colorshades',
'fields' => 'ids',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'colors_product_id',
'worth' => $product->id,
'evaluate' => '=',
)
)
);
$question = new WP_Query( $args );
if ($query->have_posts()):
foreach( $query->posts as $id ):
$Color_Code = get_post_meta($id, "color_code", true);
$R = get_post_meta($id, "red_code", true);
$G = get_post_meta($id, "green_code", true);
$B = get_post_meta($id, "blue_code", true);
$all_color_product_notification = '';
$image_url = site_url().'/wp-content/themes/porto/photographs/swatch.png';
echo '<div class="colors_box mb-4 mx-lg-4 mx-md-3 mx-2">
<a href="javascript:;" class="colorshade" model="background:rgb('.$R.','.$G.','.$B.');" ><img src="'.$image_url.'" class="img-responsive" model="width:100%; peak:70px;"></a><p> '.get_the_title( $id ).'</p>
</div>';
?>
<?php
endforeach;
endif;
As you’ll be able to see I get the publish based mostly on the meta discipline “product id”, however Meta Question returns empty.
With out the meta question I get all of the posts however I need on foundation of Ids.
Right here is the end result if I question with out Meta values:
Please information me if I’m doing one thing mistaken right here.