I create a custom field to a image gallery called views

enter image description here

My problem is how can I retrieve the field in my template gallery? See img, I'd like to display views below caption where the red arrow is pointing.

enter image description here

Any suggestions?

  • More information would be needed. Do you know what template is being used? what did you use to make the custom field? What have you tried? – rudtek Oct 18 '17 at 16:56
  • I'm using the default WP gallery template – mars Oct 18 '17 at 17:20

if your field saved as post_meta, in your page, you can retrieve it using below the code

<?php $views = get_post_meta( $current_post_id, 'views', true ); ?>

then display it using using <?php echo $view; ?>

  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Oct 18 '17 at 15:28

Thank you so much for your reply Mahmoud!

this How I'm trying to display it!

add_filter( 'use_default_gallery_style', 'mysimplefunction' );
function mysimplefunction(){
$views = get_post_meta( $current_post_id, 'views', true );
      echo '<h1>' . $views . '</h1>';

As I say I'd like it display below my gallery thumbnail ! should I use different fucntion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.