I am new to wordpress theme developments. I used ACF fields in my wordpress template. But acf fields value aren’t showed if it is not connected to page in admin dashboard.Like search.php file where wordpress redirect search to this page. At search.php, I used a template part called cta.php. It works fine with various page template say service template.
If the url becomes wordpress/post_type="post"&s="battery" then the results appear at search.php where cta.php template part also used. So, how can I set location rule for fields of cta to appear at search.php?
2
Answers
After a while I found a workaround to solve it indirectly. As, I used the template part at Home page, I can then retrieve the value of those field by using Home page id.
$home = get_page_by_path("Home"); $id = $home->ID;
Now,the_field('cta_title', $id)
gives me the value. And I can use a single location rule over there and it will be changed everywhere the template part used.There is no interface to edit the search results page, so an ACF option page will need to be created/used and that location also set for the field group. The
cta.php
template part will then need to check ifis_search()
istrue
and change where it retrieves ACF data from (untested):cta.php
:Or, if you need to be more explicit: