Home › Forums › Add-ons › Repeater Field › How to retrieve the id row dynamically from repeater
Hello everyone,
i was try to retrieve the id row dynamically from repeater (inside costume post type)
that have 4 fields:
1.report name
2.report date
3.report featerd image (simple image)
4. report file (this file is pdf)
So i need to find dynamically the id of the 4 field , Because every file is different file and i output it through Ajax , How do i need to do that ?
Now the situation is that i get the same pdf report inside 2 cubes in the front-end, i need that for every cube is different pdf.
For your reply i will very very appreciat
Thanks in advance.
Here is my code :
in Function.php:
function get_file_pdf_url(){
$post_id = $_POST['postid'];
$files = get_field('foa-reports-content-repeater',$post_id);
foreach($files as $file){
$file_url = $file['report-file-download']['url'];
}
echo $file_url;
die();
}
add_action('wp_ajax_nopriv_get_file_pdf_url', 'get_file_pdf_url');
add_action('wp_ajax_get_file_pdf_url', 'get_file_pdf_url');
in Javascript file ( i am post it anyway):
$("a.report-scale").on('click', function(e){
e.preventDefault();
$('.popup-modal.modal-overlay').addClass('visible');
/** AJAX **/
var post_id = $(this).attr('data-postid');
var data = '';
data = {
action: 'get_file_pdf_url', // function to execute
postid: post_id,// selected category lvl 1 id
};
$.post(get_pdf_file.pdf_ajax_url, data, function(response){
if(response){
/** $('.popup-modal .content').html(response);**/
PDFObject.embed(response, ".popup-modal .content");
}
});
});
I also succeeded to do var_dump ,and here i need to reach where i mark:
Array
(
[0] => Array
(
[report-name] => file name text number 1
[report-date] => 10/06/2020
[report-image] => Array
(
[ID] => 492
[id] => 492
[title] => reportExample
[filename] => reportExample.jpg
[filesize] => 81797
[url] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/reportexample/
[alt] => example 1
[author] => 2
[description] =>
[caption] =>
[name] => reportexample
[status] => inherit
[uploaded_to] => 473
[date] => 2020-06-10 13:22:34
[modified] => 2020-06-10 13:24:28
[menu_order] => 0
[mime_type] => image/jpeg
[type] => image
[subtype] => jpeg
[icon] => https://foantisemitism.org/wp-includes/images/media/default.png
[width] => 560
[height] => 470
[sizes] => Array
(
[thumbnail] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-150×150.jpg
[thumbnail-width] => 150
[thumbnail-height] => 150
[medium] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-300×252.jpg
[medium-width] => 300
[medium-height] => 252
[medium_large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[medium_large-width] => 560
[medium_large-height] => 470
[large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[large-width] => 560
[large-height] => 470
)
)
[report-file-download] => Array
(
[ID] => 491
[id] => 491
[title] => the-real-name-of-the-file
[filename] => the-real-name-of-the-file.pdf
[filesize] => 1280371
[url] => https://foantisemitism.org/wp-content/uploads/2020/06/the-real-name-of-the-file.pdf
[link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/%d7%94%d7%aa%d7%a0%d7%95%d7%a2%d7%94-%d7%9c%d7%9e%d7%90%d7%91%d7%a7-%d7%91%d7%90%d7%a0%d7%98%d7%99%d7%a9%d7%9e%d7%99%d7%95%d7%aa-%d7%91%d7%a8%d7%a9%d7%aa-%d7%93%d7%95%d7%97-%d7%91%d7%a0%d7%95%d7%a9/
[alt] =>
[author] => 2
[description] =>
[caption] =>
[name] => %d7%94%d7%aa%d7%a0%d7%95%d7%a2%d7%94-%d7%9c%d7%9e%d7%90%d7%91%d7%a7-%d7%91%d7%90%d7%a0%d7%98%d7%99%d7%a9%d7%9e%d7%99%d7%95%d7%aa-%d7%91%d7%a8%d7%a9%d7%aa-%d7%93%d7%95%d7%97-%d7%91%d7%a0%d7%95%d7%a9
[status] => inherit
[uploaded_to] => 473
[date] => 2020-06-10 13:19:55
[modified] => 2020-06-10 13:24:28
[menu_order] => 0
[mime_type] => application/pdf
[type] => application
[subtype] => pdf
[icon] => https://foantisemitism.org/wp-includes/images/media/document.png
)
)
[1] => Array
(
[report-name] => file name text number 2
[report-date] => 19/06/2020
[report-image] => Array
(
[ID] => 492
[id] => 492
[title] => reportExample
[filename] => reportExample.jpg
[filesize] => 81797
[url] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/reportexample/
[alt] => example 1
[author] => 2
[description] =>
[caption] =>
[name] => reportexample
[status] => inherit
[uploaded_to] => 473
[date] => 2020-06-10 13:22:34
[modified] => 2020-06-10 13:24:28
[menu_order] => 0
[mime_type] => image/jpeg
[type] => image
[subtype] => jpeg
[icon] => https://foantisemitism.org/wp-includes/images/media/default.png
[width] => 560
[height] => 470
[sizes] => Array
(
[thumbnail] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-150×150.jpg
[thumbnail-width] => 150
[thumbnail-height] => 150
[medium] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-300×252.jpg
[medium-width] => 300
[medium-height] => 252
[medium_large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[medium_large-width] => 560
[medium_large-height] => 470
[large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
[large-width] => 560
[large-height] => 470
)
)
[report-file-download] => Array
(
[ID] => 531
[id] => 531
[title] => sample
[filename] => sample.pdf
[filesize] => 3028
[url] => https://foantisemitism.org/wp-content/uploads/2020/06/sample.pdf
[link] => https://foantisemitism.org/reports/%d7%99%d7%95%d7%a0%d7%99-2020/sample/
[alt] =>
[author] => 2
[description] =>
[caption] =>
[name] => sample
[status] => inherit
[uploaded_to] => 525
[date] => 2020-06-25 15:20:34
[modified] => 2020-06-25 15:22:52
[menu_order] => 0
[mime_type] => application/pdf
[type] => application
[subtype] => pdf
[icon] => https://foantisemitism.org/wp-includes/images/media/document.png
)
)
)
You must be logged in to reply to this topic.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.