Home Forums Themes Support Circle How to add new Metabox to Circle Single Video, Film, Actor or Director

Tagged: 

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #782

    Hi all customer,

    In this tutorial we will help you customize to add more information you need to display in our custom post type as single Video, Film,…

    Requirements: You need know about PHP and RW Metabox and base about WP_Query. Of course you need know about CSS too. We will do example with Video Post type

    Note: Because you can keep your custom work use child theme, In this case before update our theme to latest version you need backup and store all file not in templates folder like theme-metabox.php, …

    Step 1: Add more metabox to Video Post type

    • Go to {yourwebroot}/wp-content/themes/haru-circle/framework/includes/ then open file theme-metabox.php

      • Go to line 220 you will see Video Metabox or search this word: Video metabox
      • Example we will add an metabox field name is label (Video New, Hot, Trending,…)
      • You can see example demo for Metabox here: https://docs.metabox.io/fields/autocomplete/
      • The code added will like this

    array(
    ‘id’ => ‘haru_video’ . ‘_label’,
    ‘name’ => esc_html__( ‘Title’, ‘haru-circle’ ),
    ‘type’ => ‘text’,
    ),

    • Here is result at backend:

    **********

    Best regards,

    HaruTheme

     

    • This topic was modified 5 years, 7 months ago by admin.
    • This topic was modified 5 years, 7 months ago by admin.
    • This topic was modified 5 years, 7 months ago by admin.
    • This topic was modified 5 years, 7 months ago by admin.
    • This topic was modified 4 years, 5 months ago by admin.
    • This topic was modified 4 years, 5 months ago by admin.
    • This topic was modified 4 years, 2 months ago by admin.
    #2203

    I added a Metabox to the single Film and copied it to the child theme (using the same structure).

    1. It does not show up in neither the backend nor frontend.

    2. I directly added it to the Haru Circle Theme, it only appears in the backend.

    Could you please tell me what did I miss?

    here is my code:

    array(
    ‘id’ => ‘haru_film’ . ‘_director’,
    ‘name’ => esc_html__( ‘Writer’, ‘haru-circle’ ),
    ‘desc’ => esc_html__( ‘Writer of Film.’, ‘haru-circle’ ),
    ‘type’ => ‘post’,
    // Post type
    ‘post_type’ => ‘haru_director’,
    // Field type, either ‘select’ or ‘select_advanced’ (default)
    ‘field_type’ => ‘select_advanced’,
    ‘placeholder’ => esc_html__( ‘Select Writer’, ‘haru-circle’ ),
    // Query arguments (optional). No settings means get all published posts
    ‘multiple’ => false,
    ‘query_args’ => array(
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => – 1,
    ),
    ),

    Here is how I developed the structure in child theme.
    https://prnt.sc/ldzb0l

    Do I need to add some CSS (actually I don’t need to change anything about css) ?

    I am sorry to bother you a lot, but I really need help. Thank you.

    #2224

    Hi,
    Please copy the code you have added and the result at backend.
    The code you have added have same id with existed other id.
    So maybe it will doesn’t work.
    ‘id’ => ‘haru_film’ . ‘_director’,
    Example change to:
    ‘id’ => ‘haru_film’ . ‘_writer’,
    Please change this and also you need know a little about PHP to show new field.
    Example in child theme you need show it like this:

    $film_writer_id       = get_post_meta( get_the_ID(), 'haru_film' . '_writer', true );
    $film_writer          = get_post( $film_writer_id );
    $film_writer_link     = get_post_permalink( $film_writer_id );

    To show at any position like this:

    <?php if ( isset($film_writer) && !empty($film_writer) ) : ?>
                                    <li>
                                        <span class="meta-label"><?php echo esc_html__( 'Writer', 'haru-circle' ); ?></span>
                                        <div class="meta-value">
                                            <a href="<?php echo esc_url($film_writer_link); ?>"><?php echo $film_writer->post_title; ?></a>
                                        </div>
                                    </li>
                                    <?php endif; ?>

    Hope this help!

    #2235

    Thanks for replying.

    I use the same ID(_director) is just because I really want to achieve the same content from that ID. I just want to add one more title.

    Is there any easier way to do so?

    If not, where can I add this code? To the function.php of child theme?

    $film_writer_id = get_post_meta( get_the_ID(), ‘haru_film’ . ‘_writer’, true );
    $film_writer = get_post( $film_writer_id );
    $film_writer_link = get_post_permalink( $film_writer_id );

    Thank you very much.

    #2242

    Hi,
    Please read tutorial carefully.
    You need copy this template and edit it in child theme to make your customization keep up when you update our theme to latest version:
    http://prntscr.com/lfct1c
    the template path: wp-content/themes/haru-circle/templates/single/content-film.php
    Hope this help!

    #2262

    Hi Ellie,
    I have same issue do you find a solution ? on to add the code
    $film_writer_id = get_post_meta( get_the_ID(), ‘haru_film’ . ‘_writer’, true );
    $film_writer = get_post( $film_writer_id );
    $film_writer_link = get_post_permalink( $film_writer_id );
    many thanks for your help
    Flavio

    #2263

    Hi,
    We’ll noticed and add Writer in next version!

    #2266

    It is a really a great news! Thank you very much.

    #2267

    I have not solved this yet. Since the author would add this function to next version, let’s wait for it!

    #2269

    Perfect !! in the meanwhile I have added many other field in the signle film working on the theme-metabox and content film, and seems to work!!!

    #2277

    Hi,
    But with the Writer did we need single page for each writer?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.