I created a meta box for post, named as "Resource" where I can select a value from predefined select element in the backend. And after saving it it shows in frontend. Please see the images.
Now I want this to work like tags, author and categories. When I click it will show all the posts selected with the same value. But do not know where to start.
I used Meta Box plugin and did the following codes in function.php
add_filter( 'rwmb_meta_boxes', 'resource_meta_box' );
function resource_meta_box( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'resource_box',
'title' => esc_html__( 'Resource' ),
'post_types' => array( 'post' ),
'context' => 'side',
'priority' => 'high',
'autosave' => true,
// List of meta fields
'fields' => array(
// RESOURCE BOX
array(
'name' => esc_html__( '' ),
'id' => "resource",
'type' => 'select',
// Array of 'value' => 'Label' pairs for select box
'options' => array(
'Item 1' => esc_html__( 'Item 1' ),
'Item 2' => esc_html__( 'Item 2' ),
'Item 3' => esc_html__( 'Item 3' ),
'Item 4' => esc_html__( 'Item 4' ),
'Item 5' => esc_html__( 'Item 5' ),
),
// Placeholder of Select.
'placeholder' => esc_html__( 'None' )
)
)
);
return $meta_boxes;
}
and the following code where it needed to show <?php echo rwmb_meta( 'resource'); ?>
Thanks in advance.
you should go for custom taxonomy, cause it have the features required by you inbuilt with it. paste the code given bellow in your theme functions.php file.enter code here
replace the text 'your-post-type-slug' with the post-type slug (e.g. 'post' for Posts or 'page' for Pages etc) of the post type, with which you want to associate the taxonomy.
then use bellow code to retrieve all terms created under 'resource' taxonomy
create template file, taxonomy-resource.php from archive.php to show filtered (by the newly added taxonomy) post list.
use
the_terms(get_the_ID(),'resource', $before, $sep, $after );
to show selected resources for a specific post inside loop.