Arun Shah
Arun Shah

Reputation: 39

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.

Upvotes: 0

Views: 126

Answers (2)

Raunak Gupta
Raunak Gupta

Reputation: 10809

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!

Upvotes: 1

Mary
Mary

Reputation: 96

If you want to display the content for that page, then add the_content() within your while loop. the_content() will display the page’s content. I would also add a query reset, wp_reset_query();, after the endwhile to restores the global post data to the original query.

Upvotes: 0

Related Questions