Can this type of filter please be added to the taxonomy and post object fields as well?
Hi,
So to be clear this is happening when you have a custom taxonomy field mapping the terms to the post?
I’m sure Elliot will be on it since @jcml has opened a support ticket about it.
My search page code is :
<div class="row">
<?php
$loop = new WP_Query( array(
'post_type' => 'events','posts_per_page' => -1, 'order=ASC' )
);
if ($loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'loop');
endwhile;
else :
get_template_part( 'loop', 'empty' );
endif;?>
</div>
and loop.php
content code is (for example) :
<article id="post-<?php the_ID(); ?>">
<div class="card">
<div class="card-image">
<?php
$image = get_field('event_cover');
if( !empty($image) ): ?>
<img src="<?php echo $image['sizes']['medium'] ?>"/>
<?php endif; ?>
</div>
</div>
</article>
This exact same snippet works for displaying the image of all posts in all pages…but not on search page 🙁
And 302 is the good ID (I mean, the ID of the image that should be displayed…).
Thanks for your time and help John 😉
EDIT: some more details that may help.
1) I have a taxonomy field named “event_style”. When I filter posts by this custom field it works great (The image is displayed correctly). It fails only when I use the distance filter to modify the query…
2) I have another image field displayed (as an object) in the header (so it’s outside the loop). This one doesn’t work neither when posts are filtered by distance. Works well on other pages.
You would need to create custom JavaScript for the field in question, make an AJAX request and do your own query for the select2 field of the taxonomy field. This isn’t something that you can to with ACF. You can start here: http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
Another way you could do this is to use a regular select field that you dynamically populate from the first taxonomy then create a conditional select fields that show/hide based on the selection of the first select field. A bit complicated to build.
Hi Greenhoe,
I don’t think you can easily update the taxonomy parameter of your field once the edit screen has been rendered. It would require an AJAX call and recreating the entire field dynamically..
May I suggest a different solution that’s maybe a bit easier and doable.
If you use a relationship field instead there’s a built in filter capability for taxonomies. You can set the field to only allow for 1 value so that it’ll work pretty much the same as the post_object field.
Then if you really want you should be able to create some custom Javascript for the extra functionality. Look for a change in the taxonomy dropdown and change the taxonomy filter dropdown in the relationship field accordingly. It should trigger the filtering automatically. If you also want to make sure the client can’t change the filter themselves you could just add a tiny CSS snippet to hide the taxonomy filter from them.
What do you think?
Do you mean you can’t show a taxonomy archive page.
There are other templates that are related to taxonomies. The first is
archive-somename.php
That will show an archive of all posts in a post type
Then there is
taxonomy-$taxonomy.php
where $taxonomy is the name of your taxonomy. This will show an archive of the taxonomy posts.
I was going to point you to the WP template hierarchy document, but it appears they’re in the middle of some kind of switch, the page should be here https://developer.wordpress.org/themes/basics/template-hierarchy/ but redirects to something new that isn’t their yet, how nice.
On top of that you’re working in the Genesis framwork, and that has it’s own set of rules. Functions like the ACF function the_field()
will work anywhere that a standard WP function like the_content();
will work. You need to figure out how to add basic functions and for that you really need the Genesis documentation.
Thanks, John. I have the file itself working, single-somename.php. And can get the custom post type to register in the backend but I need to learn more on making it behave with all functionality that regular posts have. That is to say, having meta data such as author name, date, etc, taxonomy type display and all. I have it now set up so that I can create the taxonomies (taking the place of “categories” for standard posts) but they don’t seem to display in the site itself. That is to say, I can’t show the archive of a taxonomy I created in the admin area.
I believe that’s related to standard WordPress code in functions.php. What I have listed above in functions.php is a start but I believe more is needed to make all aspects work properly.
I am also reaching out to the Studio Press community but no working replies as yet. Probably need more time. Thanks again for your reply.
Hey @acf-support James,
Just wanted to check in on the status of this. I’ve found another instance where this is happening now — when trying to retrieve an ACF taxonomy image from on the taxonomy page (taxonomy.php).
I can pull them in fine from other pages, but when on taxonomy.php get_field()
returns the image ID rather than the array.
I’ve just discovered this issue while working on a project with ACF Pro and WPML. Has there been any progress on fixing it?
If it’s helpful, we have reproduced the problem with basic installation of WordPress 4.2.2, ACF Pro 5.2.6, WPML Multilingual CMS 3.1.9.7 and WPML String Translation 2.1.4.
You can replicate the problem like so:
Hi @oppodeldoc
The get_field_objects() function would not work in this scenario since you are trying to query some term objects.
I would recommend you make use of a for each loop to get the terms as shown below:
<?php
$terms = get_field('taxonomy_field_name');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
This isn’t possible with the existing conditional logic, however, it could be built using what is available.
Instead of using a taxonomy field for the “Parent” category, or depending on the “Category” box, you can use a select field and then dynamically fill the select field with only top level terms. http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
Allow your select field to have a null value and then display the text field to enter a child field if the select field value is empty.
Then create an acf/save_post filter that adds the category and adds the term to the post: http://www.advancedcustomfields.com/resources/acfsave_post/
I’m sure there will be a lot of little things that you also need to deal with that I haven’t thought about.
You could also include a radio button that asks “Add new sub-cagegory?” and if the user selects yes then show the “Parent” category select field and the text box for adding the sub-category.
Hi @timo
For the tax_query
, change your code to the following:
function my_relationship_query( $args, $field, $post )
{
// increase the posts per page
$args['posts_per_page'] = 10;
$args['tax_query'] = array(
array(
'terms' => '30'
)
);
return $args;
}
Check out this link for more information: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
For accessing the term object id dynamically, you could consider using get_queried_object()
function. Here is the link to the documentation: https://codex.wordpress.org/Function_Reference/get_queried_object
In this part of your code:
<?php the_sub_field('image', $row->term_id) ?>
You need to add the taxonomy to the term id. Assuming that it is “category”
<?php the_sub_field('image', 'category_'.$row->term_id) ?>
Thanks for the info.
Yes, in a recent update, I changed the logic so that the taxonomy field will only save selected terms. This is different from the previous functionality which would also load terms connected to the post..
The reason for this change was to allow sub fields to select different sub fields but allow them to save all selections to the post.
Perhaps I should add in an extra option for taxonomy fields to allow them to ‘save’ as well as ‘load’ terms based on the post. Yes, I’ll add this in to the next version
For now, can you change your code to not use get_fields (to get the post’s terms), but instead use get_the_terms WP function?
Thanks
E
Question one:
That’s the easiest and fastest way to do it using fields. On the other hand, you could create a custom taxonomy that is hierarchical and then at the top level create the states and then on the second level you could have counties.
To do it with fields so that only the counties you want are loaded would take a lot more work, you’d need to create some custom javascript to reload the county select field whenever the state field was changed. Possible, but takes longer and the result from the users perspective will be the same.
Question 2:
I would also carefully name my county fields. If you are using the state abbr for the value of state then:
ia_county, nm_county, etc
then you can simplify getting the county
$county_field = $state.'_county';
$county = get_field($county_field)
I’m running the website fysiocursus.nl. This is directory of courses for physiotherapists. Once every month I upload a set of new courses as a concept using Really Simple CSV Importer. The custom post type and custom taxonomies are created using Types. Up to ACF 4.4.0 the uploaded taxonomy terms were reflected in the custom taxonomy field.
In 4.4.2 the oploaded terms are not reflected in the cutom field. When I tick one ore more terms in the custom field, these are saved on publication or updating the post.
Thanks for the info.
Can you confirm that the terms are saved to ‘Blog 2’ before the ‘save_post’ action is called?
Perhaps due to data available in $_POST['fields']
and cached field data that ACF is attempting to save…
Can you do some debugging in the core/fields/taxonomy.php
file.
There is a function called set_terms and perhaps this is the function which is running on blog2 when it shouldn’t be.
Can you place some debug code in that function and see if it runs on blog2? Perhaps the solution is to clear the value of $this->set_terms
after the foreach loop on line 253
Thanks
E
Hi mate,
My ACF config for the taxonomy field is only on the post type in Blog 1. In Blog 2, there are no ACF fields at all. I’m using code to transfer the terms on the post in Blog 1 to the post in Blog 2 (same post type).
The terms save fine to the post on Blog 1 and stay set as expected, however, after I manually call the save_post action while switched to blog 2, it removes the taxonomies on the post in blog 2 even though there are no ACF fields setup on that particular post type.
Make sense?
Thanks for the bug report.
When you say:
– After this the terms that I just set have now been removed from the post.
Do you mean that the taxonomy field is not showing these values?
Or do you mean that the terms are not being saved to the post at all?
Can you check your DB to confirm this?
Thanks
E
Thanks for the bug report, Can you please elaborate a bit more on the issue?
If you use the taxonomy field to select terms, doe sthe value save as normal?
Is it only when you select terms outside of the taxonomy field that the field does not show these new values?
We just had the same problem with a transition from ACF+Repeater, etc., to Pro. All our field groups but one were duplicated. The one that was not duplicated had only a single text field; each of the others had repeater, WYSIWYG and/or related post link fields.
The bad news is that in at least one case, there are two fields missing from one of the repeater fields in the older version of the field group. The portal_box field in field_group #5209 has only three fields; the one in field_group #5255 contains all five of the fields that should be there. (See attachments.) As a result, part of the portal box is not displaying.
We have no multi-language support. Here’s a list of our active plugins:
ManageWP – Worker (v4.1.6) by ManageWP
Gravity Forms (v1.9.9) by rocketgenius
Admin Quick Jump (v1.4) by James Kemp
Advanced Custom Fields Pro (v5.2.6) by elliot condon
Advanced Post Types Order (v3.6.2) by Nsp Code
BackWPup (v3.1.4) by Inpsyde GmbH
Categories Images (v2.5) by Muhammad Said El Zahlan
Cookies for Comments (v0.5.5) by Donncha O Caoimh
Duplicate Post (v2.6) by Enrico Battocchi
WordPress Editorial Calendar (v3.5) by Colin Vernon, Justin Evans, Joachim Kudish, Mary Vogt, and Zack Grossbart
Enable Media Replace (v3.0.3) by Måns Jonasson
Google Analytics by Yoast (v5.4.2) by Team Yoast
Google Calendar Events (v0.7.2) by Ross Hanney
Gravity Forms – Placeholders add-on (v1.2.1) by Joan Piedra
Gravity Forms MailChimp Add-On (v3.6) by rocketgenius
Image Watermark (v1.5.0) by dFactory
McWebby Magnific Popup (v00.01.00) by Donna McMaster
McWebby Custom Post Types (v00.02.01) by Donna McMaster (declares post types)
Media Tags (v3.2.0.2) by Paul Menard
Members (v0.2.4) by Justin Tadlock
Simple Sitemap (v1.65) by David Gwyer
Sucuri Security – Auditing, Malware Scanner and Hardening (v1.7.9) by Sucuri, INC
Category Order and Taxonomy Terms Order (v1.4.2) by Nsp-Code
ThreeWP Activity Monitor (v2.12) by edward mindreantre
WooCommerce Bulk Discount (v2.3.1) by Rene Puchinger
WooCommerce Dynamic Pricing (v2.9.6) by Lucas Stark
WooCommerce (v2.3.10) by WooThemes
WooThemes Helper (v1.5.5) by WooThemes
WordPress SEO (v2.1.1) by Team Yoast
WP Migrate DB Pro (v1.4.7) by Delicious Brains
WP SEO Humility (v0.1) by Donna McMaster
Must-use Plugins:
ManageWP – Worker Loader (v) by ManageWP
McWebby Debug Log (v0.1.0) by Donna McMaster
I opened a support ticket with ACF and am still awaiting a reply. If I hear anything on this topic I will be sure to share. I am experiencing the same issue that when I check a box for a taxonomy my entire meta box disappears. I noticed that somehow the JS is adding a hide class to the meta box after the taxonomy selection.
There is another person having this problem. http://support.advancedcustomfields.com/forums/topic/taxonomy-issues-in-version-4-4-1/#post-25862
ACF 4.4.1 changed the taxonomy field to be ready for the WP 4.2 update
4.4.1
Taxonomy field: Added compatibility for upcoming 'term splitting' in WP 4.2
Taxonomy field: Major improvement to save/load setting allowing for different values on multiple sub fields
Core: Minor fixes and improvements
This may be the same problem as this: http://support.advancedcustomfields.com/forums/topic/load-value-based-on-the-posts-terms-doesnt-work/
ACF 4.4.1 altered the Taxonomy field: Added compatibility for upcoming ‘term splitting’ in WP 4.2
This may have something to do with it.
John,
Yes , I use WP4.2.2.
No, I don’t use the same terms in different taxonomies.
I just tested it again on a local install: same problem
ACF 4.4.0 works OK, ACF 4.4.2 does not load the taxonomy terms in the custom field.
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.