[Resolved] Link between the ID of a page and the ID of its repeatable field
This support ticket is created 2 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I would like to make a breadcrumb trail.
I have Pages and Articles that list via Customs Posts the IDs of "children".
In the construction of my breadcrumb trail, I would like to: query the database (sql) from the child page/articles to know if its ID is listed in another page (which would be its parent).
Example: I have a page ID = 970 which lists in a custom post the child page ID = 977.
The problem I encounter is the following: when I search the database (SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` LIKE '977';), I get ID = 972.
It turns out that 972 is none other than the ID of one of the repeatable custom fields in the page ID = 970 : we are almost there... but we still need to make the link between the ID of the page (970) and the membership of the repeatable field (972).
Can you tell me in which table of the WordPress database is it possible to prove the link between the ID of a page and the ID of its repeatable field?
Have you created any repeatable field group? If yes, can you please share screenshot of that and on what post type you set that repeatable group to be visible/display?
My SQL query is able to find the ID of a repetable field which mentions the ID of the current page ---> I just have to find the ID of the page which has this same ID of repetable field obtained previously.
EXAMPLE:
SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` = 977 ---> Returns '972' which is none other than the ID of the custom field contained in the page '970'
So I would like to refine my query so that it returns '970' directly when I enter the page ID '977' as a parameter, which is none other than its child page
Well - I will require access details and I will require to know how you add parameter from where and then after reviewing your structure I will be able to guide you in the right direcgtion.
Please share details what ID or field you want to use where and what would be the result you want at the end with test case example. Please share what file you are using where you added the code.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've changed the code within the Ariane.php file as given under:
$ID_actuelle = $post->ID;
$Fil_Ariane = array($ID_actuelle);
function Recherche_Parent ($ID_actuelle,$flag=false) {
global $wpdb;
global $Fil_Ariane;
if(!$flag){
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` = ".$ID_actuelle.";";
$results = $wpdb->get_col($query); //echo $query.'<br />';
$parent = toolset_get_related_post($results[0],'un-enfant-listing');
array_push($Fil_Ariane, $parent);
Recherche_Parent($parent,true);
}else{
if(!$ID_actuelle){
return;
}
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` = ".$ID_actuelle.";";
$results = $wpdb->get_col($query); //echo $query.'<br />';
if(count($results) > 1){
foreach($results as $k=>$v):
$parent = toolset_get_related_post($v,'un-enfant-listing');
if(!$parent){
continue;
}else{
array_push($Fil_Ariane, $parent);
Recherche_Parent($parent,true);
}
endforeach;
}else if(count($results) == 1){
$parent = toolset_get_related_post($results[0],'un-enfant-listing');
array_push($Fil_Ariane, $parent);
Recherche_Parent($parent,true);
}
}
}
// INIT - On execute la function
Recherche_Parent($ID_actuelle);
$Fil_Ariane = array_reverse(array_diff($Fil_Ariane,[0]));
print_r($Fil_Ariane);
As this is a custom code this is the max help we can offer, you can see the result with your page:
- hidden link
I hope the solution I shared will help you to resolve your issue or you can adjust the above code as required or call our certified contractors for any further help related to such custom edits:
- https://toolset.com/contractors/