• I’m having trouble outputting the parent slug.

    Here’s what I’ve got so far (however this currently outputs nothing within the $media_items parameters):

    <?php function the_parent_slug() {
      global $post;
      if($post->post_parent == 0) return '';
      $post_data = get_post($post->post_parent);
      return $post_data->post_name;
    } ?>
    
    <?php $media_items = get_attachments_by_media_tags('size=thumb&media_tags='.$the_parent_slug); ?>

    I’ve also tried putting ‘the_parent_slug’ within an echo to see if anything is output and I get nothing.

    <?php echo '' . $the_parent_slug . ''; ?>

    Probably something simple?

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    I saw you write a function but did you run the function actually? e.g. $the_parent_slug = the_parent_slug(); And Then use the $the_parent_slug variable.

    Thread Starter surfsup74

    (@surfsup74)

    OK – I now have…

    <?php function the_parent_slug() {
    global $post;
    if($post->post_parent == 0) return ”;
    $post_data = get_post($post->post_parent);
    return $post_data->post_name;
    } ?>
    <?php $the_parent_slug = the_parent_slug(); ?>
    <?php $media_items = get_attachments_by_media_tags(‘size=thumb&media_tags=’.$the_parent_slug); ?>

    …but still get nothing in the $media_items parameters. Where am I going wrong here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help to get parent post slug’ is closed to new replies.