Home › Forums › Add-ons › Repeater Field › ACF repeater – retrieve fields
Hi there,
I’m using ACF + the repeater add-on and I have a problem I can’t solve :
– back end : a page named ‘file’ with a repeater field
– in this repeater field, two file fields named ‘file_pdf’ and ‘file_html’
– front end : with an url such as ‘/file/?ref=1234’ I retrieve the corresponding repeater
I want to be able to attach a PDF file and a HTML file to each repeater.
My code :
$current_ref = $_GET['ref'];
$current_ref_file_query = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_name = '$current_ref' LIMIT 1");
But I can’t retrieve all the sub fields attached to this repeater…
Here’s what I can retrieve :
[ID] => 233
[post_author] => 1
[post_date] => 2019-04-28 19:12:58
[post_date_gmt] => 2019-04-28 17:12:58
[post_content] =>
[post_title] => MS-CR-17
[post_excerpt] =>
[post_status] => inherit
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => ms-cr-17
[to_ping] =>
[pinged] =>
[post_modified] => 2019-04-28 19:12:58
[post_modified_gmt] => 2019-04-28 17:12:58
[post_content_filtered] =>
[post_parent] => 134
[guid] => http://www.website.com/wp/wp-content/uploads/2019/04/MS-CR-17.pdf
[menu_order] => 0
[post_type] => attachment
[post_mime_type] => application/pdf
[comment_count] => 0
As I said, I can’t retrieve the HTML field (sub_field(‘file_html’))… Please somebody can help me ?
Thanks a lot !
I have no idea by looking at your code what it should be doing, but just guessing…
post_name = '$current_ref'
are you sure that both of them have the same “post_name”
and
LIMIT 1
If they are the same name this will limit the query to only getting 1 result.
Hi,
thank you for your reply.
Yes, both fields of repeat has the same “post_name”.
Not sure to understand what you’re talking about the limit.
I tried to make a sketch explaining what I want to achieve :
Thanks again.
You have the limit on the query == 1, that means that it will only get 1 result.
I’m not sure what repeater ID you are referring to since it is not possible to query a repeater field or how that ID put in the “ref” value translates into a post name used in your query.
The topic ‘ACF repeater – retrieve fields’ 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.