M
M
mibo2015-09-25 11:34:58
WordPress
mibo, 2015-09-25 11:34:58

ACF for archive page?

Hello.
I use the ACF plugin to form additional fields in wordpress posts.
There is a post type book and there is an archive page for it archive-book.php
How to add additional fields with acf to the archive page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2015-09-27
@HeadOnFire

The question is a bit vague.
Display additional post fields in posts on the archive page? get_field(), the_field(), normally.
Or - add additional fields only for the archive page itself?
UPDATE (from comments):
You should understand how Custom Fields work in general. The fields and their values ​​are stored in the database in the wp_postmeta table. They are bound by a foreign key in post_ID, that is, the field / fields are tied to a specific post (of any type - post, page, custom post type). The architecture does not allow binding abstractly to the archive page, that is, Custom Fields are not suitable for this task.
But there are other solutions. The simplest and most obvious is the wp_options table. There you can save any keys with any values ​​that do not have an explicit binding to any object (post, page, etc). To work with options, there are add_option(), get_option(), update_option(), delete_option() functions.
If we are talking only about archives of taxonomies (headings, tags, custom taxonomies), then you can look towards termmeta. This is a complete analogue of wp_postmeta, which allows you to add custom fields for taxonomy terms (not for the entire taxonomy, but for specific terms, that is, specific categories or tags). This is not currently a standard table, but in version 4.4. (December 2015), maximum 4.5 (April 2016) this functionality will already be added to the kernel. In the meantime, you can use the plugin for this -https://wordpress.org/plugins/wp-term-meta/
Regarding ACF for these tasks. If you have a free version, then this functionality is not available. If you have the Pro version, then it has such a thing as Option pages - the ability to create your own settings pages and fill in the necessary fields. This feature just allows you to create a settings page, add fields to it with links to archives and create the necessary settings and fields to solve your problem. But, I repeat, this is only in ACF 5 Pro (in the 4th version it is a separate module for the options pages, but it makes no sense to buy a license for the 4th version now).

D
dariabichan, 2022-02-11
@dariabichan

Faced the same problem too. Here is the solution: just in the archive-slug.php archive file, explicitly specify the post ID in the the_field (or get_filed) function parameters - the_field('name', 4575);.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question