Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter Stephiew

    (@stephiew)

    Figured it out! I’m going to post the code that worked for if anyone else wants to do what I am doing.

    <?php
    ob_start();
    $aside = $post; echo $post->post_name;
    do_action('after_aside', $aside);
    $aside = preg_replace('/(\-profile)/','-aside$0',"-aside");
    echo $aside;
    $aside = ob_get_contents();
    ob_end_clean();
    
    $page = get_posts( array( 'name' => $aside ) );
    
    if ( $page )
    {
        echo $page[0]->post_content;
    }
    
    ?>

    So basically, I put all the code that turns the current post name from name to name-aside, and put it inside the object, then fetch it with my variable name (‘$aside = ob_get_contents();’) so when I put it into get_posts, it goes to find the constructed slug.
    This is going to be helpful because I am working on a company website, where we want profiles to be a post, and then have a sidebar with additional information about the person in question. The people doing the posting from now on do not know code, so I am making it simple for them. All they need to do is make their posts, and name the slugs accordingly (name and name-aside) for it to be constructed for them automatically!
    Best part: no plugins or widgets used!

Viewing 1 replies (of 1 total)