0

I have created a page called Projects. I then created 4 pages that are children of the projects page. I have some code that creates a link on all of the children pages that when clicked, will take you to a template that is set for a page called "All Projects". What I need to do is get an array of the project page ID's and send them to the template page. So right now, I have them and it works like this

inside functions.php

function tb_child_pages($childID){
    $args = array(
    'child_of' => $childID,
);
   $childPages = wp_list_pages($args);
}

and in the project page

 global $post;
$direct_parent = $post->post_parent;

echo 'the page' . tb_child_pages($direct_parent);
?>

that will print out a link to the 4 pages on the projects page. How can I get the id's into the all projects template without doing some hard code by name? I want to use the id's in case the name should ever change.

  • in this code, there is no hardcoding because you search the identifier of the parent of the current page. which part of your code do you want to be more dynamic ? – mmm Jan 11 '18 at 7:20
  • I figured it out. I am using serialize to pass the id's through an anchor link but it makes a pretty ugly address. I am now looking for a way to make it look better. It passes this in the address bar ?pageIDs=a:4:{i:0;i:944;i:1;i:17;i:2;i:19;i:3;i:1310;} – Jamie Jan 12 '18 at 1:18
  • edit your question to show us the code which use this argument pageIDs – mmm Jan 12 '18 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.