• Resolved ekdor

    (@ekdor)


    Hi, I am using the following code in many places successfully.

    <?php $id = 1000; $p = get_page($id); if ( get_post_status ( $id ) == 'publish' ) { echo apply_filters('the_content', $p->post_content); } ?>

    For those wanting to use it, that php code grabs the contents of page with id 1000 and inserts it in the same location as that code. Very useful.

    But I have one instance where I would like that pages title as well as its content. As best I can figure I could add a second filter to include the_title to the_content but I don’t know how to do that or if it’s even a good approach.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This is going to be waht you need”

    $id = 1000;
    
    if ( get_post_status ( $id ) == 'publish' ) {
    	$p = get_post( $id );
    	
    	echo '<h2>' . apply_filters( 'the_title', $p->post_title ) . '</h2>';
    	echo apply_filters( 'the_content', $p->post_content );
    } // if ()

    I’ve done a few things here to help out.

    First, the call to get_page() should be get_post(). get_page() has been deprecated, so don’t reply on it. get_post returns the exact same data anyway.

    Second, I’ve moved the get_post() call inside the if() statement. The reason for this is that there’s no reason to call it unless the status is correct.

    Third, I’ve added in the extra line for the title. It’s set there using H2 tags, but you can change that to anything that you want it to be.

    Thread Starter ekdor

    (@ekdor)

    Awesome work! Thanks for your quick help and the description.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add content from page to post including title’ is closed to new replies.