• Resolved Sykat

    (@sykat)


    I am just started. I added a post type called videos and added a custom field named video_link. then I tried to add that custom field in my single-video.php with that
    <?php echo get_post_meta($post->ID, ‘video_link’, true); ?>
    but that is not showing the YT link.
    https://i57.tinypic.com/wmnl7p.jpg
    I even tried that in loop of recent post but not working:

    <div class="section group">
    <?php
    //WordPress loop for custom post type
     $my_query = new WP_Query('post_type=videos&posts_per_page=9');
          while ($my_query->have_posts()) : $my_query->the_post();
    	  ?>
              <div class="col x4 vid_list">
         <a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?> Video Download"><img src="<?php echo get_post_meta($post->ID, ‘video_link’, true); ?>" alt="<?php the_title(); ?>" /></a><br/>
    	<a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?> Video Download"><?php the_title(); ?></a>
      </div>
    
    <?php endwhile;  wp_reset_query(); ?>
    
    </div>

    it output an empty value

Viewing 4 replies - 1 through 4 (of 4 total)
  • C W (VYSO)

    (@cyril-washbrook)

    You’re using curly quotes instead of straight quotes…

    Thread Starter Sykat

    (@sykat)

    Then please tell me the fixed code

    C W (VYSO)

    (@cyril-washbrook)

    My reply contained both the problem and the solution. I’m really not sure what more there is to say.

    Thread Starter Sykat

    (@sykat)

    My problem solved.. It never had any error. I used video link as custom field name and renamed it video_link later. but the id i think didn’t rename. So the return value was null. I deleted that custom field and added new field named video_link and the code works.
    But tell me one thing… What is the id if I use space in custom field name?
    As example, for a space name, is it
    get_post_meta($post->ID, ‘a space name’, true); ?
    It doesnt work.
    or get_post_meta($post->ID, ‘a%20space%20name’, true); ?
    or get_post_meta($post->ID, ‘a-space-name’, true); ?
    or get_post_meta($post->ID, ‘a_space_name’, true); ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP custom field is not working..!’ is closed to new replies.