I have to get specific page content (like page(12))
I used that :
<?php $id=47; $post = get_page($id); echo $post->post_content; ?>
Work nice execpt for compatibility with translations, it returns both French and English text
But the loop is fine, return only the good language version
<?php if(have_posts()) : while(have_posts()) : the_post(); ?> <div id="post"> <?php the_content(); ?> </div> <!-- .post -->
So the question.... HOW to get a specific page content inside the loop...
If you need to get the page ID you can easily do this by logging into your WordPress website admin and opening the page, post or custom post type for editing. The page id is visible in the address bar as shown in the screenshot below.
get_page( int|WP_Post $page, string $output = OBJECT, string $filter = 'raw' ) Retrieves page data given a page ID or page object.
I've answered my own question. Call apply_filter
and there you go.
<?php $id=47; $post = get_post($id); $content = apply_filters('the_content', $post->post_content); echo $content; ?>
get page content by page name:
<?php $page = get_page_by_title( 'page-name' ); $content = apply_filters('the_content', $page->post_content); echo $content; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With