admin管理员组

文章数量:1332865

** This is my code **

        <?php echo get_avatar( get_the_ID() ); ?>
        <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
            <h4><?php echo get_the_author_meta('display_name', $author_id); ?></h4>
        </a>
        <!-- end author name and image -->

        <p class="p-text">
            <?php the_author_description(); ?>
        </p>
        <!-- end author description -->

        <ul class="social-links">
            <li><a href="#"><i class="fa fa-facebook"></i></a></li>
            <li><a href="#"><i class="fa fa-twitter"></i></a></li>
            <li><a href="#"><i class="fa fa-dribbble"></i></a></li>
            <li><a href="#"><i class="fa fa-behance"></i></a></li>
        </ul>
        <!-- end author social media icons -->
        
        <img src="<?php echo get_post_meta( get_the_ID(), 'author_sign', true) ?>" alt="">

        <p><?php echo get_post_meta( get_the_ID(), 'author_text', true ) ?></p>
        <!-- end author sign here -->
        
    </div>
    <!-- end author information -->

** This is my cmb2 code **

    $author_data = new_cmb2_box( array(
    'id'      => 'author_metabox',
    'title'   => __( 'Custom Author Information', 'bounty' ),
    'object_types'  => array( 'user' ),
  ) );

  $author_data->add_field( array(
    'id'      => 'author_sign',
    'type'    => 'file',
    'name'    => __( 'Upload Author Sign: ', 'bounty' ),
    'options' => array(
      'url' => false
    )
  ) );

** This is my code **

        <?php echo get_avatar( get_the_ID() ); ?>
        <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
            <h4><?php echo get_the_author_meta('display_name', $author_id); ?></h4>
        </a>
        <!-- end author name and image -->

        <p class="p-text">
            <?php the_author_description(); ?>
        </p>
        <!-- end author description -->

        <ul class="social-links">
            <li><a href="#"><i class="fa fa-facebook"></i></a></li>
            <li><a href="#"><i class="fa fa-twitter"></i></a></li>
            <li><a href="#"><i class="fa fa-dribbble"></i></a></li>
            <li><a href="#"><i class="fa fa-behance"></i></a></li>
        </ul>
        <!-- end author social media icons -->
        
        <img src="<?php echo get_post_meta( get_the_ID(), 'author_sign', true) ?>" alt="">

        <p><?php echo get_post_meta( get_the_ID(), 'author_text', true ) ?></p>
        <!-- end author sign here -->
        
    </div>
    <!-- end author information -->

** This is my cmb2 code **

    $author_data = new_cmb2_box( array(
    'id'      => 'author_metabox',
    'title'   => __( 'Custom Author Information', 'bounty' ),
    'object_types'  => array( 'user' ),
  ) );

  $author_data->add_field( array(
    'id'      => 'author_sign',
    'type'    => 'file',
    'name'    => __( 'Upload Author Sign: ', 'bounty' ),
    'options' => array(
      'url' => false
    )
  ) );
Share Improve this question asked Jul 6, 2020 at 20:17 JohnyJohny 35 bronze badges 1
  • The registration code shows that you have registered fields for a user, and the screenshot seems to confirm that. For user meta, you need to use get_user_meta(), so I'm not sure why you are using get_post_meta() to get the data. – Fränk Commented Jul 7, 2020 at 14:19
Add a comment  | 

1 Answer 1

Reset to default 0

According to CMB2 documentation, instead of

<img src="<?php echo get_post_meta( get_the_ID(), 'author_sign', true) ?>" alt="">

you should use something like

<?php echo wp_get_attachment_image( get_post_meta( get_the_ID(), 'author_sign', true ), 'medium' ); ?>

or

<img src="<?php echo wp_get_attachment_image_url( get_post_meta( get_the_ID(), 'author_sign', true ), 'medium' ); ?>" alt="">

本文标签: pluginshow to display data from user panel using cmb2 metabox