Search code examples
phpwordpresswhile-loophook-wordpress

How to : Populate Content of Page to another page in WordPress


I am using OptionTree for WordPress option panel, I am getting the page ID, and using that page ID I want to populate the content of the page to another page. Here is my code:

<?php 
$test_input = ot_get_option( 'for_myapp_features' );
?>
<?php $the_query = new WP_Query( 'page_id=$test_input' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post();  ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile;?>

Any help would be helpful.


Solution

  • You can use get_post_field and get_the_title() to get content and title.

    $test_input = ot_get_option('for_myapp_features');
    
    echo get_post_field('post_title', $test_input); // to get the title
    //or
    //echo get_the_title($test_input); // to get the title
    echo get_post_field('post_content', $test_input); //to get the content
    

    Hope this helps!