• Resolved watermelonkid

    (@watermelonkid)


    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?

    https://www.ads-software.com/extend/plugins/custom-field-suite/

Viewing 15 replies - 1 through 15 (of 25 total)
  • 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: https://uproot.us/custom-field-suite/documentation/get/

    Thread Starter watermelonkid

    (@watermelonkid)

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

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

    Thread Starter watermelonkid

    (@watermelonkid)

    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

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

    global $cfs;

    Thread Starter watermelonkid

    (@watermelonkid)

    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.

    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)?

    Thread Starter watermelonkid

    (@watermelonkid)

    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 https://amtimemusic.com/design

    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…

    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 https://validator.w3.org/

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

    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 https://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.

    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 ‘[Plugin: Custom Field Suite] No Value Returned’ is closed to new replies.