I’m displaying a loop of custom post type. The custom fields are displaying correctly, however I can’t get the subfields to display.
In this case I’ve created a custom field named project_description with a subfield called sub_heading within a group called Project Page.
This is what I’ve done so far. Can anyone tell me what I’m doing wrong?
<section class="services-section">
<div class="container services-section-container">
<h1 class="fp-header extended-black-l">Featured Projects</h1>
<?php
$featuredProjectSection = new WP_Query(array(
'posts_per_page' => 10,
'post_type' => 'project'
));
while($featuredProjectSection->have_posts()) {
$featuredProjectSection->the_post(); $i++; if(($i % 2) == 0) { ?>
<div class="row splitcontent-services">
<div class="col-lg-6 col-6 services-img-left">
<img src="<?php the_field('top_image') ?>">
</div>
<div class="col-lg-6 col-6 services-content-right">
<h2 class="condensed-semibold-l"><?php the_title(); ?></h2>
<?php if( have_rows('project_description') ): ?>
<?php while ( have_rows('project_description') ) : the_row();
$subhead = get_sub_field('sub_heading');?>
<h3 class="regular-m"><?php echo $subhead; ?></h3>
<?php endwhile; ?>
<?php endif; ?>
<button class="extended-black-s"><a href="<?php the_permalink(); ?>">Learn More ></a></button>
</div>
</div>
Hello,
After a custom post type is saved, I hook on the action “acf/save_post” so I can create a category with the post name, then I update a taxonomy field of the custom post type with the id of this category.
When I clic on publish the post, the taxonomy field ( a select) is still empty. But If I check the database, it is filled correctly. So I refresh the page, and now the taxonomy field is displaying the correct value in the dropdown.
My code in functions.php :
add_action('acf/save_post', 'save_commune');
function save_commune( $post_id ) {
global $post;
$cat_id = wp_create_category( $post->post_title, 0 );
update_field('cat_id', $cat_id, $post_id );
}
Any ideas on how I can see a correctly displayed field after publishing a post without refreshing the whole page manually ?
Hi all,
I’m currently having issues running queries based on the Date Picker field and comparing this with the current date. I’ve opted to set the Return Format to “U” so that it returns a string which I can then compare to a string version of the current date.
What I would like to do is display content on certain pages based on this comparison (greater than current date for “coming soon” and also the opposite for “now showing”). However, it seems that the data is getting very mixed up as I have content that should be on “now showing” which is displaying on “coming soon” instead.
In addition I have the page split so that I can use an ACF to set certain films to be “featured” and therefore not show up in the lower results as well.
Below is the code I have so far and a live deployment can be viewed on the following.
<?php
get_header();
?>
<!-- START - Coming Soon -- Header -->
<section class="comingsoon-header">
<h1 class="section__heading">Coming Soon</h1>
<!-- START - Coming Soon Slider -->
<?php
$dateToday = date("U"); ?>
<p><?php echo $dateToday ?></p>
<?php
$comingSoonFilms = new WP_Query(array(
'post_type' => 'film',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'film_releasedate',
'value' => $dateToday,
'type' => 'DATE',
'compare' => '>',
),
array(
'key' => 'film_active',
'value' => '1',
),
)
));
?>
<?php if ($comingSoonFilms->have_posts()) : ?>
<!-- START - Coming Soon Slider -->
<div class="section__slider-container text-center">
<div class="swiper swiper-container swiper--section swiper--section--filmswide swiper--section--filmswide--comingsoon">
<div class="swiper-wrapper">
<!-- Slides -->
<?php while ($comingSoonFilms->have_posts()) {
$comingSoonFilms->the_post();
if (get_field('film_comingsoon_featured_status') == true) {
?>
<div class="swiper-slide">
<a href="<?php the_permalink(); ?>">
<img src="<?php the_field('film_comingsoon_featured_image'); ?>" alt="" title="" class="swiper__imgbg" />
<div class="comingsoon-header__details">
<p class="comingsoon-header__details__heading"><?php the_title() ?> </p>
<span class="cta">View More</span>
<p class="comingsoon-header__releasedate"><i class="fas fa-clock"></i>Coming: <?php echo date('d/m/Y', get_field('film_releasedate')) ?><br />
<br /><?php echo get_field('film_releasedate') ?></p>
</div>
</a>
</div>
<?php
}
}
?>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</div>
<!-- END - Coming Soon Slider -->
</section>
<!-- START - Coming Soon -- More -->
<section>
<h2 class="section__heading">More Coming Soon</h2>
<div class="filmpanels filmpanels--grid">
<?php while ($comingSoonFilms->have_posts()) {
$comingSoonFilms->the_post();
if (get_field('film_comingsoon_featured_status') == false) {
?>
<div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php echo wp_get_attachment_url(get_field('film_poster')); ?>" alt="" title="" class="swiper__imgbg" />
<p><?php the_title(); ?></p>
<?php echo date('d/m/Y', get_field('film_releasedate')) ?>
<p><?php echo get_field('film_releasedate') ?></p>
</a>
</div>
<?php
}
}
?>
</div>
</section>
<section class="results--pagination">
<?php
echo paginate_links(array(
'total' => $comingSoonFilms->max_num_pages
));
wp_reset_query();
?>
<?php else : ?>
<p>No films currently coming soon!</p>
<?php endif; ?>
</section>
<?php
get_footer();
?>
https://apexcinemas.andrewcourtney.co.uk/coming-soon/
Thanks in advance
Hi team,
Recently my ACF fields meta box is not displaying under the ACF group. I have tried toggling the checkbox for “Fields” under the display options, you can see a slight expansion, but the meta box doesn’t show.
I have already tried to disable all the plugins and changing the theme, to no avail. I have Version 5.11.4.
Any advise would be helpfu.
Please see screehsot
So… I have been using ACF fields on my WooCommerce pages for more than a year now (December 2020 to be exact). And everything has been working perfectly.
But since this week, the ACF field displays on the product pages have simply gone.
Nothing has changed (apart from auto-updates of plugins). But some reason the product pages are not displaying the values from the ACF fields in WooCommerce.
Can anyone offer any advice?
Hi everyone,
I would like to use an ACF field to inject Schema merkup to a few specific pages on my WordPress website. Some of them are custom taxonomies or custom post types.
After a two hour research on the topic, I am still stuck.
I have created a text area field called “schema_code” and entered the desired Schema markup for some of my sub pages.
I currently use this code in my functions.php which does not do anything:
function acf_header_script() {
$schema = get_field('schema_code');
echo '<script type=application/ld+json>' . json_encode($schema_code) . '</script>';
}
add_action ( 'wp_head', 'acf_header_script' );
What am I missing here? Thanks a lot!
Im currently working on this project which regards Teams and Players. For the project I have created two CPT’s called Teams and Players.
The idea is to create a ton of players in the backend and create a handful of teams and have teams players linked to teams with the relationship field. Now I’m running into some issues, which I cannot seem to figure out. I will describe them below:
I want to create the possibility to only add a Player to a single team.
If a team is already assigned, then it should not be able to go into another team and assign this very same player. So if possible I need to disable moving player X into team B, if player X is already assigned to team B.
My current construction for this is a relationship field which is added to the Teams CPT with field name teams_players
On the player overview page, I want to display the team which the player is assigned to
On the player overview page Im loading all players as a card by wp_query. Now I want to somehow display the post title of the team which has this player assigned (relationship field is: teams_players and is added to the Teams CPT).
On the player single page, I also want to display the post title of the team which has the player assigned.
This one is very similar to the previous case. But instead of displaying it on an overview page where the players are loaded by wp_query, this is regarding the single page of the player post type. Which I think will a different code.
I hope I have made my struggles clear enough to understand. Hope somebody is able to help me out with this one.
Thanks in advance 🙂
Hi there!
I’m having a little trouble getting the User field to display the image, everything else is working perfectly well and it’s even pulling through the url when i check in the inspector however when i hover over the url i get a popup saying ‘could not load the image’.
Since everything else it working I’m thinking this might be a gravatar or possibly a browser issue.
Code snippet included below ::
$nomInfo = get_sub_field('staff_member'); ?>
<div class="nomination-block col-12 col-md-4 text-center">
<h3><?php the_sub_field('nom_ranking'); ?></h3>
<img src="<?php echo esc_attr($nomInfo['user_avatar']); ?>" alt="author-avatar" />
<h3><?php echo $nomInfo['display_name']; ?></h3>
<p><?php the_sub_field('staff_content');?></p>
</div>
If anyone has any insight into this I’d be really grateful!
Hi there,
I facing problem with ACF fields (with advanced forms) by using inside Elementor popups.
The form and fields are displaying but there are not initialized, google maps doesn’t load, submit button too. I think this is just because there are not initialized because Elementor popup doesn’t exist when acf load. So I got no JS working.
Is there a way to completely re-init all the ACF fields ? I Got a hook to detect when popup is fired, so I just need to load fields at this moment.
Thanks
Hi there, I’m using a custom field of type “Date Time Picker” with the Return Format set to F j, Y g:i a (January 13, 2022 6:00 pm). However, the date is displaying on the page as “2022-01-13 18:00:00”. To display the custom field on the page, I’m using Ele Custom Skin.
I’ve been reading the tutorials and documentation, and I understand the php needed to alter the format manually. I just don’t know which specific files to add that code to, or if that’s even necessary. Shouldn’t the Return Format take care of it?
Thanks so much in advance.
Hey there,
My issue is when I duplicate or clone a page, the page is set to Draft and my ACF fields for that page never show up.
It’s not that the information is not being copied over, the fields themselves just never show in the Gutenberg page editor.
I have to go to the Field Group and add a new rule to display the fields on the Draft page. For example the fields will appear on Home Page but not Home Page – Draft.
Is there anyway to make the fields appear on draft pages? Or do I have to go and change it in the field group everytime?
Thanks
Hello,
I have the basic ACF plugin and I can’t display the select choice of a dropdown.
No problem with displaying text fields with get_fields, for instance : <?php echo get_field(‘titre_vo’); ?>
but when I try it with a select choice nothing appears.
I’m really a newbie, so I’m sorry if my question has alredy been covered, I tried a lot of things but nothings works, at best it display “empty” or “array” when I try something other than get_field.
Thanks a lot for your assistance!
When creating a new field, the setting where you need to specify the conditions for displaying this field is, after saving the created field, the settings where the condition for displaying the fields is shown is not shown and the field is not displayed on the desired page. What could be the reason?
Hi there,
I am wanting to display a custom field on my woocommerce category page. I have created a custom field called test_field. This is showing on my product category page fine, but I cannot get it to show on the front end.
I am trying this in my functions.php as as this is the file I am using to edit the category page.
echo the_field('test_field');
However, nothing is showing.
Can anyone tell me what I have done wrong?
thanks!
I need to generate a table that loops through users and displays 2 columns: 1) the user display name; and 2) a frontend-editable text area labeled ‘status”. The purpose is to allow user to edit not only their own status, but also any other user’s status.
I assume that I need to use acf_form(), and maybe(?) a repeater field. What’s the most straightforward way to accomplish this? Do I need to create individual user status posts and use a repeated field for the form?
I already have a custom user status field. But I’m a bit confused about how to set up a repeater field and combining it with acf_form() for displaying the editable status form.
Hello,
I am using ACF Version 5.10.
When I created a field(ex: Questions_display_time) and assigned a value to it from jQuery..it is displaying and showing in the form UI also. But the problem is with when I use this value in conditional logic it’s not working. I used js in functions.php file. What could be the reason and how to solve it?
please do the needful ASAP. I am attaching the ACF form pic also
This is how iam assigning value in JS (functions.php):
acf.add_action('ready', function( $el ){
const child_created = $('#date_diff').val();
//setting value to Questions_display_time
$('input[name="acf[field_61237a721a448]"]').attr('value',child_created);
});
I am experiencing ACF wisywyg fields not showing its formatting options on certain pages. I checked the settings in field groups and it is toggled on visual and text. what can be the cause of the problem. it is ok in other pages.
I’m using this code to display taxonomy terms:
<?php
$features = get_field('grid_selected_features');
if( $features ): ?>
<ul>
<?php foreach( $features as $term ): ?>
<h2><?php echo esc_html( $term->name ); ?></h2>
<?php echo esc_html( $term->description ); ?>
<a href="<?php echo esc_url( get_term_link( $term ) ); ?>">View all '<?php echo esc_html( $term->name ); ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
The permalinks are working, but the term name is not displaying.
I am working on a site that would have an option page, so that not one will break the design. So for example, we have added some fields, for example, contact. I figure I take the short code and do this, [acf field="contact"] and place it in the page with the design. BUT nothing.
All seems to work fine. Any help?
Thank you,
We moved a site to a new hosting platform(Hostgator)
after to move the fields do not display
Location is set to post type = show
I tried adding to show on page = home and the do not show there either.
any thoughts
Hi,
I’m creating a dynamic website where users can get to know the status of their business request. I collected their image as profile picture in ACF and trying to display on their login page. But, when I import through elementor to display in the front end dashboard, it is not displaying. None of the custom fields can be displayed, only image field cannot be displayed.
Please help me out.
Hi there,
I am trying to create a custom RSS feed. So far, I have a template in my theme folder that is responsible for outputting the RSS: https://tozsdeforum.hu/feed/
Now here’s the code for it:
<?php
/**
* RSS2 Feed Template for displaying RSS2 Posts feed.
*
* @package WordPress
*/
header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; charset=' . get_option( 'blog_charset' ), true );
$more = 1;
echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
/**
* Fires between the xml and rss tags in a feed.
*
* @since 4.0.0
*
* @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments',
* 'rdf', 'atom', and 'atom-comments'.
*/
do_action( 'rss_tag_pre', 'rss2' );
?>
<rss version="2.0"
xmlns:hst="http://hirstart.hu/rss-mod"
<?php
/**
* Fires at the end of the RSS root to add namespaces.
*
* @since 2.0.0
*/
do_action( 'rss2_ns' );
?>
>
<channel>
<title><?php wp_title_rss(); ?></title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod>
<?php
$duration = 'hourly';
/**
* Filters how often to update the RSS feed.
*
* @since 2.1.0
*
* @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly',
* 'yearly'. Default 'hourly'.
*/
echo apply_filters( 'rss_update_period', $duration );
?>
</sy:updatePeriod>
<sy:updateFrequency>
<?php
$frequency = '1';
/**
* Filters the RSS update frequency.
*
* @since 2.1.0
*
* @param string $frequency An integer passed as a string representing the frequency
* of RSS updates within the update period. Default '1'.
*/
echo apply_filters( 'rss_update_frequency', $frequency );
?>
</sy:updateFrequency>
<?php
/**
* Fires at the end of the RSS2 Feed Header.
*
* @since 2.0.0
*/
do_action( 'rss2_head' );
while ( have_posts() ) :
the_post();
?>
<item>
<title><?php the_title_rss(); ?></title>
<?php
$post_id = get_the_ID();
$kiemelt = get_field( 'kiemelt_cikk' );
if ( $kiemelt == TRUE ) :
$output = '<hst:titlepage>1</hst:titlepage>';
endif;
echo $output;
?>
<link><?php the_permalink_rss(); ?></link>
<?php if ( get_comments_number() || comments_open() ) : ?>
<comments><?php comments_link_feed(); ?></comments>
<?php endif; ?>
<dc:creator><![CDATA[<?php the_author(); ?>]]></dc:creator>
<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
<?php the_category_rss( 'rss2' ); ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if ( get_option( 'rss_use_excerpt' ) ) : ?>
<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
<?php $content = get_the_content_feed( 'rss2' ); ?>
<?php if ( strlen( $content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>
<?php if ( get_comments_number() || comments_open() ) : ?>
<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link( null, 'rss2' ) ); ?></wfw:commentRss>
<slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php endif; ?>
<?php rss_enclosure(); ?>
<?php
/**
* Fires at the end of each RSS2 feed item.
*
* @since 2.0.0
*/
do_action( 'rss2_item' );
?>
</item>
<?php endwhile; ?>
</channel>
</rss>
Now this is the important part:
$post_id = get_the_ID();
$kiemelt = get_field( 'kiemelt_cikk' );
if ( $kiemelt == TRUE ) :
$output = '<hst:titlepage>1</hst:titlepage>';
endif;
echo $output;
For some CPT’s I have a ‘kiemelt_cikk’ checkbox ticked. If this box is ticked, I would like to add a namespace to the RSS. The issue is, that regardless of it being ticked or not, the namespace gets added currently. What might I be doing wrong?
Thanks!
I am working on building a video custom post type and as part of it I want to pull information from a team member custom post type to display with the videos.
Here is an example:
https://stglawkam.wpengine.com/pa-vid/5-reasons-every-parent-needs-an-estate-plan/ (This is a single post from the custom post type pa-vid)
https://stglawkam.wpengine.com/focus-areas/litigation/ (This is a standard page)
If you open the video there is a call and email button that is using a relationship field to connect the video to an attorney post and that info is pulled from from fields on the attorney post.
It works great on individual video pages and normal pages, but I also am displaying the videos on the blog feed and another custom post type and there the attorney data doesn’t get pulled at all: https://stglawkam.wpengine.com/news-media/ (this is just the standard blog feed I modified to display the pa-vid custom post type along with the normal posts) https://stglawkam.wpengine.com/team/joseph-a-zarlengo/ (this is an attorney post type where the relationship is supposed to pull data from)
Is there some gotcha or extra step I need to keep in mind when building this functionality to work certain page types to make sure it functions everywhere?
Hi there,
I just saw this topic: https://support.advancedcustomfields.com/forums/topic/acf-fields-not-displaying-on-posts-page/
It’s essentially what I have. I load custom fields in the blog page (template: home.php), but it’s showing content from the first blog post instead.
The problem with the solution above is my setup is a lot more complex than this. Looks something like this:
– home.php refers to flexible-content.php, which contains the loop to check for repeater fields.
– If the page contains a repeater ‘block’, it will then load /acf/block-hero.php for example, I use about 10-14 various blocks
So I might use the “Block Hero” on top of the blog, then add the post loop under that.
So just passing the blog post ID for each ACF field would be tens if not hundreds of fields. Essentially also complicating or breaking the ‘default’ ACF functionality.
Is there any way to force ACF to get the blog post any other way? I’ve considered wrapping the entire ACF element in some kind of global variable ID, but the page is already returning the correct page ID…? Even querying the object from within the block-hero.php returns the correct blog page ID, but it’s simply not showing any of that content.
Any ideas?
Best,
Dave
Hi all,
Just recently i have been working on a website for a client and came across a problem displaying a header, but only when the field is populated.
As you can see below i am using an h2 header inside the ‘if( have_rows )’ function. This is to display the header only if there is content in the sub_field.
The problem is that in some instances it shows the header if the sub_field is empty, but only in certain circumstances.
1. In the initial instance when the sub_fields are new and have not been used, the h2 does not display.
2. When the sub_field/sub_fields are populated the h2 displays.
3. But when the sub_field/sub_fields have been populated, but subsequently that data has been removed, the h2 still displays. Also, the ‘<div class=”column”>’ also still displays but with no content inside it.
So my question is, am i doing something wrong, or is this the way it works?
If the latter, then how do i get around the h2 and div displaying when the sub_fields have had their content removed?
Hope someone can help.
<div class="exhibitor_videos">
<?php // Check rows exists.
if( have_rows('exhibitor_videos') ):
// Show header
echo '<h2 class="entry-header">Video Gallery</h2>';
// Loop through rows.
while( have_rows('exhibitor_videos') ) : the_row();
// Load sub field value.
$exhibitor_video = get_sub_field('exhibitor_video');
$exhibitor_video_title = get_sub_field('exhibitor_video_title');
// Do something...
echo '<div class="column">';
echo do_shortcode("[video src=" . $exhibitor_video . "]");
echo '<p>' . $exhibitor_video_title . '</p>';
echo '</div>';
// End loop.
endwhile;
else : // No value.
// Do something...
endif;
?>
</div>