Home › Forums › Backend Issues (wp-admin) › Rewriting Metadata
I have setup a custom content type (Groups) and I’m using a checkbox advanced custom field called ‘region’ The regions are 1,2,3,4 or 5. I define a region when creating a new group. I am doing some troubleshooting, so I installed the “Post Meta Inspector” to see if the custom metadata was actually holding as it should.
Instead of the metadata for ‘region’ being stored as, for example, ‘1’ it is being stored as ‘a:1:{i:0;s:1:”1″;}’
I’ve tried to look for conflicting plugins that might be causing the metadata rewrite, but I’m not having any luck. The end goal is to accomplish something along the lines of what is presented in this tutorial:
http://www.advancedcustomfields.com/resources/tutorials/creating-wp-archive-custom-field-filter/
Any thoughts?
If I go into the database and manually change the region from
a:1:{i:0,s:1:”1″} to 1
Then when I do a filter on http://www.takeajourney.org/groups/?region=1, everything works just fine. If not, then I get this error:
Warning: Invalid argument supplied for foreach() in /home/takeajou/public_html/wp-content/themes/journeychurch/archive-groups.php on line 34
In the code, this is line 34:
`<?php foreach( $field[‘choices’] as $choice_value => $choice_label ): ?>
You have assumed that the data is incorrect, when in fact, the data is perfectly fine.
A checkbox can save multiple values, therefore, it will save it’s data as a serialized array.
Please leave the data as it originally was. If you want the value ‘1’ to be saved for WP_Query meta_key filtering, then please use a radio button instead of a checkbox.
The radio button, or select field will save the value as a string (un-serialized) because only 1 vaue can be saved.
Does that help?
Thanks
E
hey elliot,
that makes sense. so i don’t know if this should change forum feeds or not, but here is my archive page:
http://www.takeajourney.org/groups/
i have 5 regions that i’m trying to filter by. if you try any of these filter urls, they do not work:
http://www.takeajourney.org/groups/?region=1
http://www.takeajourney.org/groups/?region=2
http://www.takeajourney.org/groups/?region=3
http://www.takeajourney.org/groups/?region=4
http://www.takeajourney.org/groups/?region=5
where would my error be? in the function.php file or the archive.php file?
i’m trying to accomplish what you’ve done in this tutorial:
http://www.advancedcustomfields.com/resources/tutorials/creating-wp-archive-custom-field-filter/
thanks!
The code in your functions.php file will need to be modified to look for the $_GET value within the serialised array string.
If you look at the docs for the checkbox field, you will notice that one of the code examples hows how to filter posts via a checked value:
http://www.advancedcustomfields.com/resources/field-types/checkbox/
Changing your meta_query to use a LIKE compare as shown in the code example will correct your code.
Thanks
E
The topic ‘Rewriting Metadata’ is closed to new replies.
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.