Home › Forums › Backend Issues (wp-admin) › show articles with category (food)
Good morning,
I try to explain the problem well.
I installed the ACF Plugin for the following reason (to have a group where I manage 3 fields).
Dettagli ACF:
1) I created a group with ACF with the following name: (Menu Details)
2) inside the group created ACF I created 3 fields
nome – type Text
ingredienti – type Text
prezzo – type Number
3) once created the group and the fields with ACF I went to the articles section of WordPress and I created 2 articles
Menu item (with the following menu CATEGORY)
Deliver item (with the following delivery CATEGORY)
*once I have created the two articles and compiled the ACF FIELDS INSIDE THE TWO ARTICLES I created a file inside the WP-CONTENT / THEMES / BETHEME / page-acf.php line 47 to 78 code and I customized the graphics I want to use with the ACF fields that I extract (I ATTACH FILE WITH THE ACF CODE + GRAPHICS).
IMPORTANT QUESTION: inside the file I created to extract and display the information entered in the ACF fields and see them in the front-end part of the website, I must always specify the following code for each field:
<?php the_field(‘nome_piatto’, 383); ?>
<?php the_field(‘ingredienti_menu’, 383); ?>
<?php the_field(‘prezzo’, 383); ?>
BUT I ALWAYS HAVE TO SPECIFY (POST_ID) instead I would like to specify not the post_id but the (category ID) that I put on each article … otherwise I would have to create that <? Php the_field (‘price’, 383); ?>
ACF fields are tied to individual posts, not categories. If you want to display the fields dynamically without specifying a post ID, simply use:
php
Copy
Edit
<?php the_field(‘nome’); ?>
<?php the_field(‘ingredienti’); ?>
<?php the_field(‘prezzo’); ?>
This will automatically pull the data from the current post. However, if you need to filter and display fields based on a category, you’ll need to query posts assigned to that category and retrieve their ACF fields. You can apply this to any menu listing or structured content, like on mangmenuprices.ph, where details such as names, ingredients, and prices need to be dynamically managed.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.