1

So right now the site automatically creates pages when a post is updated. I want this page to include an audio playlist. So what I do, is simply add the shortcode: [playlist]. Then, when the audio files are attached to the page, the playlist automatically generates.

I can confirm that this method works with specified IDs.

The problem is, that 3 different pages are made, and I need the audio to be attached to all three pages. So my solution is that I make a another page, set the audio files as children to that page, and make the original 3 pages children of the new page. Then I could use the [playlist] shortcode, but tell it to get the id from the parent page.

Example:

[playlist id="<?php get_parent_id ?>"]

or something like this.

The problem is that I cannot get the parent id. I've tried multiple different lines of code and nothing will work. The playlist just gets the default 0 ID, which it does when id="" is left blank.

This is all going into the functions.php file in my theme's directory.

--

Maybe there is a better way to do this, thusfar, this seems like the simplest solution, if only I can get the direct parent ID. It must exist.

0

Have you tried the following function:

<?php get_post_ancestors( $post-ID ) ?>

The last post in the returned array should be the highest level ancestor.

This is from the Codex.

  • Thank you for replying! This actually returns a 1 when I print it, which I am still trying to understand. – Nicholas Kearney Feb 20 '17 at 14:38
  • It should return an array; using this in your page template, see if you can print_r the returned value and check out the array. The last item should be the highest level ancestor. – Svartbaard Feb 20 '17 at 14:46
  • I solved it, I posted my solution. Thanks for your help, I used your advice to get the ID. – Nicholas Kearney Feb 20 '17 at 15:44
0

Here is my solution:

Catalogue is a custom field in my post.

I make a 'dummy' page with just the catalogue number and attach the MP3s to this page.

$catalogue = get_field('catalogue');
$parent_id = get_page_by_title(strtolower($catalogue));  
$direct_id = $parent_id->ID;
$promo_page_content = [playlist id=" . $direct_id . '"]';

I realize this is most likely not the best way to write this. I am new to PHP. But for now, this will put it together. Hope this helps anyone else having the same problem.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.