Custom ACF field – Zero as value

Posted in: Newspaper
Post count: 26

Hi,

when the custom ACF field is empty, by default its hidden, but i have an ACF which can take the value of zero, the theme is considring it empt and it wont show it at all. how can this be fixed?

thanks,

Post count: 35449

Hi,
Can you please let me know the acf filed type you are using? some screenshots with the settings made and filed type will help us to identify the problem.
Thank you!

Post count: 26

The field type is number with no special settings, whenever trying to display it and the value is 0 it will not show up, for now i used a code based soloution as workaround. but there is an issue, as i am using template to display my taxonomy page, the term ID will always show the template ID and not the actual taxonomy ID, is there a way or helpful function that your theme use to reterive the single post or single taxonomy archive page ID post_id or term_ID?

Post count: 35449

Hi,
Can you please provide a few screenshots with the settings in acf and the page were the element should be display so I can recreate the situation and show it to a developer?
If you try to use the get_post->ID or get_the_ID() will return the cloud template id (if is used a cloud template).
You can try:
$url = 'https://example.com/your-post-slug/';
$post_id = url_to_postid( $url );
echo 'Post ID is: ' . $post_id;

or
td_global::get_instance()->td_post_id;

Thank you!

Post count: 26

Please see the SS below, it shows that the ACF type is just a text, and its value is 0 and when that happened it wont be displayed on the front end and will be hidden. so not sure how to tweak that, so it does show the zero value.

Post count: 35449

Hi,
It appears this is a known situation in acf plugin – https://i.imgur.com/nmRm4EJ.png
Solutions, if you use that field for numbers, replace the text field with a numeric field.
Another solution is to set 0 to 0.0. It works as long as there is another character around the 0
Thank you!

Post count: 26

Okay, will try the change to numeric field and see if that work

  • This reply was modified 1 year by kindghost.
Post count: 26

changing it to Numberic type didnt work as well, it still not showing.

As you can see on the same thread from ACF team, they mentioned the issue with the logic code before displaying, if its using simple if else or empty it wont show the 0.

  • This reply was modified 1 year by kindghost.
Post count: 35449

In this situation, the only option is to use another element besides 0, any element that can be interpreted as text and not as a value.

Post count: 26

Okay, i am trying to use shortcode to handle the displaying of those ACF fields, but inside the module builder it doesnt seems to work as i cant get the ID of that specific post displayed using the module.

tried those:
$url = ‘https://example.com/your-post-slug/’;
$post_id = url_to_postid( $url );
echo ‘Post ID is: ‘ . $post_id;

or
td_global::get_instance()->td_post_id;

and
global $tdb_state_single;
$post_id = $tdb_state_single->post_id->__invoke();

but none works.

thanks,

Post count: 35449

Hi, I’ve asked a developer to look into it and provide a solution. As soon as I hear back from him, I’ll let you know.

Post count: 26

Thanks for this.

Viewing 12 posts - 1 through 12 (of 12 total)
The forum ‘Newspaper’ is closed to new topics and replies.