I'm having trouble showing ACF on a custom taxonomy page.
The custom tax is 'destinations' with the page being taxomony-destinations.php the field is called 'destination_landing_image. I'm trying to display it on 'mysite.com/destinations/coutryname' as follows:
<?php if (have_posts()) : while (have_posts()) : the_post();
$destination_landing_image = get_field('destination_landing_image');
<img src="<?php echo $destination_landing_image['url'] ?>" alt="<?php echo $destination_landing_image['alt'] ?>">
<?php endwhile; endif; ?>
Oddly enough the page in question does show up the ACF fields within the custom post type(holidays) which is lower in the page. So I guess firstly am I calling it correctly within the loop? and Secondly is a custom taxonomy the right type of page to use?
When you use ACF with posts you can just use get_field() as you are, but when you use it with anything else such as taxonomies, users or options, you need to give ACF a hint about how to look it up. In this case you need to tell it what taxonomy and term you are specifically targeting. Luckily both WordPress and ACF make this really easy:
//Ask WordPress for the currently queried object
//http://codex.wordpress.org/Function_Reference/get_queried_object
$obj = get_queried_object();
//Pass that object as a second parameter into get_field
$destination_landing_image = get_field( 'destination_landing_image', $obj );
Related
I am trying to display Advanced Custom Field on my WooCommerce storefront in html list tag. I modified the file:
content-product_cat.php
from this:
<li <?php wc_product_cat_class( '', $category ); ?>>
to this:
<li style="background: <?php the_field('my_ACF_field'); ?>" <?php wc_product_cat_class( '', $category ); ?>>
And also I added ACF field on my WP backend and assigned it to my page called "Store" which is the WooCommerce storefront. I can fill the input on my backend (Store page) but it's not showing on storefront/category page, it's just not passing. Where is the problem?
I also tried to set this field as taxonomy, and display it on category setting in WooCommerce, also without success.
I think you'll need to use the second parameter on ACF the_field, to get the value for the specific object that you're after. E.g. if you have the ACF Field set on a product category, you'll need to pass in the term that you're currently looking at to get the right value.
I believe that on a category page you'll need to use something like
<li style="background: <?php the_field('my_ACF_field', $category);?>" <?php wc_product_cat_class( '', $category ); ?>>
This ACF documentation field gives more detail about adding fields to taxonomy terms: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
This is my first post on stackoverflow, as I am quite new to PHP. I am learning the language to help me customize my online portfolio in Wordpress, and I usually manage to make the changes I need - but not this time, apparently.
I am trying to use get_post_meta to read a meta tag in my portfolio pages, and avoid displaying the page thumbnail. This is the code I am using:
<?php $disable_thumb = get_post_meta( get_the_ID(), 'minimal_portfolio_page_thumb', true );
if( $disable_thumb !== 'on' ): ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php endif; ?>
<?php endif; ?>
Using a meta tag management plugin, I added the following tag to all my "portfolio"-type pages:
<meta name="minimal_portfolio_page_thumb" content="on">
I am currently checking if this works in this page of my web: egozalor.com/portfolio/hansel-gretel/
Long story short, the trick does not work as expected. I guess there is something I am doing wrong or not realizing, due to my little knowledge of PHP. Any indications, tips or recommendations are very welcome!
Also please let me know if further or more specific information is necessary to assess my issue.
Thanks in advance!
The function get_post_meta has nothing to do with the <meta> elements of your site. With this function you can only get metadata of the post itself. You can set the metadata on each post at the end (custom fields) as key / value pairs.
These custom fields are not visible on the site itself. You can create a custom field on every post with key minimal_portfolio_page_thumb and value on (or another value like 0/1).
Looks like the custom fields are disabled by default on WordPress. But you can enable the custom fields without an additional plugin. On the top right of your post you can find three dots to open a menu. At the end of the menu there is the entry "Options". On the options you can enable the custom fields.
You can enable the custom fields for posts and pages.
i'm trying to build a movie slider for a Cinema tv screen.
I started to build custom Fields using acf advanced custom fields in wordpress.
Everything is working except displaying acf metadata with more options.
The revolution slider and the grid now displays it like the word (array)
image displaying array
this is what I use to display custom fileds in the sliders
**in cornerstone**
{{acf:field_name}}
**in sidebar**
[acf field="field_name"]
**in the grid**
#meta:field_name#
**in revolution slider**
{{meta:field_name}}
**in template**
*// simple*
<?php the_field('field_name'); ?>
*// multiple options*
<?php
// vars
$values = get_field('field_name');
// check
if( $values ): ?>
<ul>
<?php foreach( $values as $value ): ?>
<li><?php echo $value; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
How can I make this work so it displays more options, like on the template page
Can somebody please help me
Problem is that when using the {{meta:somemetatag}} filter with rev slider, it bypasses the acf helper functions, such as get_field(), that handle the heavy lifting involved when navigating the various types of objects and arrays when using the more complex ACF fields. So the trick to getting those values to display properly in your rev slider is to use the native ACF shortcodes in combination with the revslider {{id}} filter.
For example, if you're attempting to display the return values from an acf select field in a post based Revolution Slider you could try the following:
[acf field="my_acf_field_name" post_id="{{id}}"]
This will output the my_acf_field_name ACF field for the current post being rendered by Revolution Slider.
I am loading a field in the header of my wordpress website. This field is displaying a text on top.
<?php the_field('text_on_top'); ?>
Every page display it, the name of the field is exactly the same on every ACF page. My problem : the blog / post page doesn't load that field. What is going wrong ?
use : the_field() to get_field() ;
<?php echo get_field( "text_on_top" ); ?>
Get a value from a specific post
$value = get_field( "text_on_top", $post->ID);
More details
I have created a custom post type called:'activities' and created a taxonomy for it called: 'activity_locations'. I have then added a custom field to the taxonomy for an image using Advanced Custom Fields, this image field is called: 'activity_location_image'
On the single template I have managed to display the taxonomy for the product with the following code:
Available in: <?php the_terms( $post->ID, 'activity_locations', ' ', ' / ' ); ?>
However I need to elaborate on this to add a small image after the taxonomy text. I have tried the following code but it hasn’t worked (nothing is displaying):
<?php
$term = get_field('test');
if( $term ): ?>
<img src="<?php echo get_field('activity_location_image', $term); ?>" />
<?php endif; ?>
Can anyone offer any advice/assistance on how to make this work?
If you are still on the single template page, then get_field() without a second argument will only be fetching metadata for your current post object, not the related term objects.
If you read the documentation for get_field() you'll see that to query for term fields you need to use the format
get_field('field_name', 'taxonomyname_X)
Where taxonomyname would be activity_locations and X would be the term ID.
Since you want to customize the display and use the data about the terms, you'll have to swap the_terms() with wp_get_post_terms() which will give you an array of term objects. You can then loop over the array, grabbing the image for each term and outputting the HTML to display the term.