WordPress.org

Support

Support » Plugins and Hacks » Custom Field Suite » [Resolved] [Plugin: Custom Field Suite] No Value Returned

[Resolved] [Plugin: Custom Field Suite] No Value Returned

  • I cannot get any values to return using the code provided. Can someone show me a code example that actually pulls custom field data associated with the current page?

    For example, I need to echo the value of a select box that associates a single value with every page. So in my template, I have tried several different ways of trying to echo the value associated with the current page:

    <?php
    $loop = new WP_Query();
    while ( $loop->have_posts() ) : $loop->the_post();
    $field = $cfs->get('pdf_chapter_association'); ?>
    
    <h1><?php echo $field; ?></h1>
    
    <?php endwhile;
    wp_reset_query(); ?>

    Doesn’t return anything.

    Then outside the loop:
    <?php $field = $cfs->get('pdf_chapter_association'); ?>

    Doesn’t return anything.

    What am I doing wrong?

    http://wordpress.org/extend/plugins/custom-field-suite/

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author logikal16

    @logikal16

    watermelonkid – try this:

    <?php $field = $cfs->get('pdf_chapter_association', get_the_ID()); ?>

    $cfs->get() automatically finds the post ID within the standard Loop. Since you’re using a custom WP_Query, you need to pass the post ID in manually.

    More info: http://uproot.us/custom-field-suite/documentation/get/

    No dice. The error I’m getting (and was getting before):

    Fatal error: Call to a member function get() on a non-object

    I just tried again putting it into the standard loop, and with no loop. Same result:

    Fatal error: Call to a member function get() on a non-object

    Plugin Author logikal16

    @logikal16

    Weird. Can you try adding the following line above your while loop?

    global $cfs;

    Getting closer. Now:

    <?php
    global $cfs;
    if (have_posts()) : while (have_posts()) : the_post();
    $field = $cfs->get('pdf_chapter_association');
    echo $field;
    endwhile;
    php endif; ?>

    Returns “Array”, though I have my select set to a single choice–not multiple.

    If I change to:

    <?php global $cfs;
     if (have_posts()) : while (have_posts()) : the_post();
    $field = $cfs->get('pdf_chapter_association');
    foreach ($field as $value) :
    echo $value;
    endforeach;
    endwhile;
    endif; ?>

    Nothing returns. Thanks for your help with this. Starting to wonder if it’s some kind of conflict or something.

    Plugin Author logikal16

    @logikal16

    watermelonkid – I’ll look into this further. If it turns out to be a bug, I’ll get it patched shortly.

    By the way, are other field types displaying correctly for you (e.g. text fields)?

    Scratch that–it was something on my side. All good! The last solution worked.

    This is extremely perplexing!! the code works in Google Chrome but not in Safari or Firefox?? Please help!!

    function am_display_blogloop()  {  
    
    	/* Extremely Important, this allows Custom Field Suite to work */
    	global $cfs;	
    
    	if (have_posts()) :  while (have_posts()) : the_post(); ?>
    
    			<div class="my-box">
    				<div class="boxgrid peek">  
    
    					<div class="boxcaption">
    				        <h3><a href="<?php echo $cfs->get('post_link'); ?>" target="_blank"><?php the_title();?></a></h3>
    				        <h4><a href="<?php echo $cfs->get('post_link'); ?>" target="_blank"><?php the_content();?></a></h4>
    					</div>
    					<a href="<?php echo $cfs->get('post_link'); ?>" target="_blank"><img src="<?php echo $cfs->get('am_image'); ?>" class="cover" /></a>
    				</div>
    			</div>
    
    			<?php endwhile; else: ?>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    		<?php endif;  ?>
    
    <?php
    }

    In chrome, the correct fields are entered in the href and src attributes but in Safari and Firefox, the attributes are left empty??? I can’t even begin to understand why this would happen…

    you can view the live example at http://amtimemusic.com/design

    Plugin Author logikal16

    @logikal16

    Looks fine to me…

    Thank you for your quick reply logikal. It looks fine because I already switched my custom fields to the Advanced Custom Fields plugin. But my statements above were still true…

    Plugin Author logikal16

    @logikal16

    In chrome, the correct fields are entered in the href and src attributes but in Safari and Firefox, the attributes are left empty

    Both CFS and ACF are server-side plugins. The same data is being returned, regardless of which browser is used.

    The only difference is how each browser handles invalid HTML. If you had quotes within your “post_link” field, each browser handles the error a little differently.

    Had you stuck with CFS a little longer, I would’ve asked you to validate your HTML using http://validator.w3.org/

    Hi,
    I’m trying to figure out which custom fields plugin to use – how are CFS and ACF different, better, etc

    Plugin Author logikal16

    @logikal16

    It’s true that both plugins are similar.

    I created CFS because ACF kept breaking whenever a plugin update was released. I needed a solid plugin for client sites.

    ACF requires payment for certain field types. CFS is 100% free.

    Feature-wise, they’re similar. ACF has a few more field types, but CFS makes it easy to add custom field types.

    CFS is more lightweight, and has a more powerful developer API (see http://uproot.us/custom-field-suite/documentation/save/ ).

    I’m with you. I need something solid that won’t slow down my client’s sites or break on updates. I’m used to building ecommerce sites where creating custom pages using templates and native php code rather than plugins. With the myriad of plugins in WordPress I’m finding that one can easily create “spaghetti-ware” affecting the site’s performance.
    With that said, I’m going to try out CFS right now.
    Thanks for your help. Also, if you know of any other light-weight plugins that would be useful for a CMS WP site development, I’d love to hear your recommendations.

    Plugin Author logikal16

    @logikal16

    Yeah, it is sometimes hard to find decent plugins.

    Some plugins I’ve relied on in the past include:

    Widget Logic
    WP Router (slight learning curve)
    WP-PageNavi
    W3 Total Cache (only necessary for really high traffic sites)

    Some of my other plugins you might like:

    Shortcode Manager
    Advanced Custom Sort

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘[Resolved] [Plugin: Custom Field Suite] No Value Returned’ is closed to new replies.
Skip to toolbar