Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to create metabox like category #1038

Closed
Muhammad-Russell opened this issue Dec 22, 2016 · 1 comment
Closed

how to create metabox like category #1038

Muhammad-Russell opened this issue Dec 22, 2016 · 1 comment

Comments

@Muhammad-Russell
Copy link

Muhammad-Russell commented Dec 22, 2016

I created a new metabox using the plugin "Meta Box" I used following codes:

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 line of codes to show it <?php echo rwmb_meta( 'resource'); ?>

It works fine, but I want to work it like the tags, categories or author does. Make it clickable and when it is clicked it will show all the post under that item and also make it searchable. I tried a lot but couldn't find how.

I also tried to use taxonomy and create new categories, I create the category it also works fine it works same as I wanted, it creates the url also but it shows 404 page when clicked. The template file is not assigning to that url.

If you can show me a how I can complete it by using this plugin or how to assign the template though its not relates to this plugin. But this would be a great help for me.

Thanks in Advance

@rilwis
Copy link
Member

rilwis commented Mar 4, 2017

Hi,

The select field doesn't add a new URL structure to the frontend or handle the query for you. So, if you want it to work similar to categories, you must build a query by your own, using the meta value as a filter. Here is how to do that:

https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
http://www.deluxeblogtips.com/search-all-custom-fields/

If you use a custom taxonomy and see the 404 error, please try refresh the permalink (just go to Settings > Permalinks and update). Also look at the code that register that taxonomy. If that's a big trouble for you, you might want to use the MB Custom Post Type plugin, which does that quite well.

@rilwis rilwis closed this as completed Mar 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants