watermelonkid
Member
Posted 7 months ago #
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/
logikal16
Member
Posted 7 months ago #
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/
watermelonkid
Member
Posted 7 months ago #
No dice. The error I'm getting (and was getting before):
Fatal error: Call to a member function get() on a non-object
watermelonkid
Member
Posted 7 months ago #
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
logikal16
Member
Posted 7 months ago #
Weird. Can you try adding the following line above your while loop?
global $cfs;
watermelonkid
Member
Posted 7 months ago #
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.
logikal16
Member
Posted 7 months ago #
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)?
watermelonkid
Member
Posted 7 months ago #
Scratch that--it was something on my side. All good! The last solution worked.
andr923
Member
Posted 4 months ago #
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
logikal16
Member
Posted 4 months ago #
andr923
Member
Posted 4 months ago #
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...
logikal16
Member
Posted 4 months ago #
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/
rshandel
Member
Posted 4 months ago #
Hi,
I'm trying to figure out which custom fields plugin to use - how are CFS and ACF different, better, etc
logikal16
Member
Posted 4 months ago #
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/ ).
rshandel
Member
Posted 4 months ago #
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.
logikal16
Member
Posted 4 months ago #
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
rshandel
Member
Posted 4 months ago #
Thanks. What about WP super cache? I don't have plugins loaded and am just designing the site now and the page load is very slow. Its seem super cache will serve static pages so the pages will load alot faster.
logikal16
Member
Posted 4 months ago #
I've used W3 Total Cache in the past without any problems. I don't have much experience with Super Cache.
I don't have plugins loaded and am just designing the site now and the page load is very slow.
If your site is running slow without any plugins, then caching isn't going to help much. You'll need to figure out the underlying issues.
For example, if your web server is running out of memory, performance will be poor. If your database is being used by a bunch of other high-traffic sites, then you might need to adjust its configuration.
logikal16
Member
Posted 4 months ago #
If you need help specifically for Custom Field Suite, consider joining the forums: http://uproot.us/forums/
andr923
Member
Posted 4 months ago #
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.
Logikal, I am no programming genius, but I am aware that PHP is server side and therefore should output the same information regardless of browser. Nonetheless I am still confident I was getting that error. I've since tried your plugin on a different site and it is working great. Either way, I wanted to thank you for your hard work and for a great plugin. I really appreciate your effort in creating the plugin and in turn for your support in implementation. Without kind people like you, I don't know what my websites would look like...
rshandel
Member
Posted 4 months ago #
Hi logikal,
I'm just getting to install your plugin now... another plugin question for capability issues - Have you used WPSEO (Yoast SEO) or AllinOneSEO (or any other SEO plugin) -Are there other you'd recommend? If so, have you encountered any conflicts with your plugin. I've heard from others, including the author, that WPSEO has problems with ACF plugin...
Thanks again for your help.
rshandel
Member
Posted 4 months ago #
Logikal, I am no programming genius, but I am aware that PHP is server side and therefore should output the same information regardless of browser.
I'm experiencing a similar issue where different browsers are creating different results; FF is showing data correctly and IE and Chrome are not showing the data at all. The page is html validated - never experience browser dependent results in pulling data from a mysql db??....
Here's the link:
http://50.116.66.243/~ab27853/patient-services/injury-evaluation-and-treament/
andr923
Member
Posted 4 months ago #
Another issue I've found is that when clicking "Add Row" in my posts for a looped field, add row actually adds two rows instead of one. Also, the WYSIWYG editor is unusable when adding a row until i publish or update the page at which point it expands and I can use the box appropriately. Any way to add the insert media button to the WYSIWYG editor?
logikal16
Member
Posted 3 months ago #
Try upgrading to CFS 1.3.3.
andr923
Member
Posted 3 months ago #
Thanks Logikal. The latest update (1.3.5) makes it so the text editor is immediately usable when I add a row which is great cause I no longer have to update the page. But, "add row" still adds TWO rows, not ONE for some reason. Also, there is no option for editing html, or adding any sort of media (images etc...) which obviously would be great.
logikal16
Member
Posted 3 months ago #
@andr923 -
Thanks. I'll look into that loop issue, and for adding images into the wsiwyg field.
As for the code editor, click on the far right wysiwyg button ("show kitchen sink"). The "HTML" button is on the second row.