Skip Navigation

[Resolved] Not Returning Custom Field Content at all

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 10 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 12 replies, has 2 voices.

Last updated by Andrew 9 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#212370

I've created the following:

<?php $fridayvid = types_render_field("friday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$fridayvid; ?>" frameborder="0" allowfullscreen></iframe>

the custom field 'friday-video-id' is a text field; no values are returning - what am I missing?

#212423

Hi andrew,

I can not duplicate same problem in my localhost,
Types types_render_field default output custom fields of current post
I suggest you try debug your codes line by line, like this:

<?php
echo "get_the_ID()": get_the_ID(); // check if it output the correct post ID
$fridayvid = types_render_field("friday-video-id", array( )); 
...
?>

If not, for example if your post ID is stored ad $post_id
you can assign $post_id to Types function like this:
$fridayvid = types_render_field("friday-video-id", array( 'post_id'=>$post_id));

#212983

Thanks - I will debug this evening and see if it solves the problem or I can see what it is returning instead.

I'll report back my findings/results

#213026

Please let me know if you need more assistance

#213144

Luoy - your code suggestion caused syntax errors - I was not able to debug at all.

Additionally - it seems types is not returning any values when called via types_render_field in my PHP

<?php $ticketlink = types_render_field("ticket-link", array()); ?>
<a class="share_link" href="<?php echo $ticketlink;?>"></a>

The above returns no value - even though there is data in the field. here's what the HTML looks like

<a class="share_link" href=""></a>

I'm not sure why the plugin is not functioning as it says to use it via the Types Field API suggestions. Am i missing something?

#213170

please modify it like this:

<?php
echo get_the_ID(); // check if it output the correct post ID
$fridayvid = types_render_field("friday-video-id", array( )); 
...
?>
#213249

That returns the number '22'

The page ID for the page that the custom field is pulled from is '41'

#213430

Could you post the entire codes of this file, I need check which var store correct post ID.

#213442
<div id="upcoming-events">
	<div class="container">
    	<div class="row">
        	<div class="col-lg-12">
            	<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Slider Widget') ) : ?><?php endif;?>
            </div><!-- /.col-lg-12 -->
        </div><!-- /.row -->
        <div class="row row2">
        	
            <!-- LOOP START --> 
<?php wp_reset_query(); //WP_Query Arguments 
$today = date('Ymd');
$todaytime = strtotime($today);
$ticketlink = types_render_field("ticket-link", array());
$args = array(
           'post_type' => 'events',
           'meta_query' => array(
           array (
                    'key' => 'wpcf-event-start-date',
                    'value' => strtotime($today),
                    'compare' => '>='
                 )
            ),
           'orderby'   => 'wpcf-event-start-date',
           'meta_key'  => 'wpcf-event-start-date',
           'order'     => 'ASC',
           'posts_per_page' => 4
       );
?> 
			<?php $the_query = new WP_Query( $args ); ?> 
				<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> 
                 <?php $startdate=get_post_meta($the_query->post->ID,'wpcf-event-start-date',TRUE);?> 
					<div class="col-md-2">
                       
						<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'medium' );?><div class="overlay"></div></a> 
						<div class="event-info"> 
							<p class="date"><span><?php echo date('m',$startdate); ?></span><span>/<?php echo date('j',$startdate); ?></span>
                            <small><?php echo date('l',$startdate); ?></small></p>
                            <a href="<?php the_permalink() ?>" class="i_link"></a>
                            <a class="share_link" href="<?php echo $ticketlink;?>"></a>
						</div> 
					</div><!-- /.col-md-2 --> 
				<?php endwhile;?> 
			<!-- LOOP FINISH -->
                        
<div class="col-md-4">
            	<div class="row"><a href="#"><img src="<?php echo get_bloginfo ('template_url'); ?>/images/btn-view-all-events.jpg" width="360" height="161" border="0" class="img-responsive" /></a></div><!-- /.row -->
                <div class="row"><a href="#"><img src="<?php echo get_bloginfo ('template_url'); ?>/images/btn-table-reservations.jpg" width="360" height="161" border="0" style="margin-top:10px;" class="img-responsive" /></a></div><!-- /.row -->
            </div><!-- /.col-md-4 -->
        </div><!-- /.row2 -->
    </div><!-- /.container -->
</div><!-- /#upcoming-events -->
<div id="photo-gallery">
	<div class="container"></div><!-- /.container -->
</div><!-- /#photo-gallery -->
<div id="video-gallery">
	<div class="container">
    	<h4>Latest Videos</h4>
    	<div class="col-md-6">
            <?php
			 echo get_the_ID();
			 $fridayvid = types_render_field("friday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$fridayvid; ?>" frameborder="0" allowfullscreen></iframe>
            </div><!-- /.col-md-6 -->
        <div class="col-md-6">
        	<?php $saturdayvid = types_render_field("saturday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$saturdayvid; ?>" frameborder="0" allowfullscreen></iframe>
        </div><!-- /.col-md-6 -->
    </div><!-- /.container -->
</div><!-- /#video-gallery -->
#213485

Please try this:

...
wp_reset_query();
$fridayvid = types_render_field("friday-video-id", array( )); 
...

wp_reset_query() restores the $wp_query and global post data to the original main query.
http://codex.wordpress.org/Function_Reference/wp_reset_query

#213496

I have done this - and it still isn't placing the value.

<div id="video-gallery">
	<div class="container">
    	<h4>Latest Videos</h4>
    	<div class="col-md-6">
            <?php
			 wp_reset_query();
			 $fridayvid = types_render_field("friday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$fridayvid; ?>" frameborder="0" allowfullscreen></iframe>
            </div><!-- /.col-md-6 -->
        <div class="col-md-6">
        	<?php $saturdayvid = types_render_field("saturday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$saturdayvid; ?>" frameborder="0" allowfullscreen></iframe>
        </div><!-- /.col-md-6 -->
    </div><!-- /.container -->
</div><!-- /#video-gallery -->
#213573

the wp_reset_query allowed for the ID to now display the proper page ID - but the $fridayvid argument displays nothing still when echoed. I've modified the code to the following and it's outputting nothing still.

<div id="video-gallery">
	<div class="container">
    	<h4>Latest Videos</h4>
    	<div class="col-md-6">
            <?php wp_reset_query();
echo $fridayvid;
			 $fridayvid = types_render_field("friday-video-id", array("output" => "raw")); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$fridayvid; ?>" frameborder="0" allowfullscreen></iframe>
            </div><!-- /.col-md-6 -->
        <div class="col-md-6">
        	<?php $saturdayvid = types_render_field("saturday-video-id", array( )); ?>
            <iframe width="500" height="281" src="<?php echo "//www.youtube.com/embed/".$saturdayvid; ?>" frameborder="0" allowfullscreen></iframe>
        </div><!-- /.col-md-6 -->
    </div><!-- /.container -->
</div><!-- /#video-gallery -->
#213708

Luoy - I want to thank you for your help - I was able to solve the problem using the post meta value call I found in the types documentation - a little bit more coding, but it works!

Thanks for all your help!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.