Support » Fixing WordPress » list child and grandchild pages with custom fields

  • I want a list of child pages with custom fields — and if there are grandchild pages a nested list of grandchild pages with custom fields.

    I made a theme and maintain a site for a bike club. The list I described above would list their single-day events with (custom fields) date and location — a nested list would show their multiple-day event series each with its own (custom fields) date and location.

    See what I hard coded here — if I could automate it with a loop, it would update whenever my client adds a new event.

    Can you suggest some code? I would like it to work on the Events page and in the sidebar. I cannot write PHP from scratch. Thank you for help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Dash10


    Forum Moderator

    well I don’t know how good you are with PHP but the process would be a somewhat simple.

    I have to do the same thing but for attached files downloads.. I know it is not for you but it uses somewhat the same thing you need to do.

    $post_meta = get_field('attachment_files');
    										// Get the number of the files that are attached to the post
    										$num = count($post_meta);
    										//print $num;
    										if ($num > 0){
    										//print $post_meta[0]['attachment_file'];
    										if (!$post_meta[0]['attachment_file'] == ''){
    										for ($i = 0; $i < $num; $i++) {
    											// Get just the title of the file and strip any errors if any
    											$old = get_the_title($post_meta[$i]['attachment_file']);
    											$new = str_replace(get_the_title(),'', $old);
    											// Ouput of each file in a list
    											print '<a class="download_attachment" href="' . wp_get_attachment_url($post_meta[$i]['attachment_file'])  . '" title="Download This Flier" target="_blank"><img src="'.home_url().'/wp-content/themes/black/assets/img/icons/pdf-icon.jpg" width="15"/>' . $new . '</a> <br />';

    I hope it guides you in somewhat of the right idea on how to get it working

    Justin, I looked at your code, but I am so inexperienced with PHP that I cannot decipher it. If anyone else has a snippet of code that comes closer to solving the problem described above, I would really appreciate seeing it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘list child and grandchild pages with custom fields’ is closed to new replies.