How to get complete content for a single post that was splitted into pages - wordpress

I have a WordPress post which was divided into multiple pages using pager break <!--nextpage--> tag and it's pagination functionality is working as expected for single post page.
www.example.com/url-post-content/1
www.example.com/url-post-content/2
www.example.com/url-post-content/3
But problem is my category page where i am showing all posts for a category with pagination(single post on each page).
I want to show complete content of the post(without pagination) on my category post page because here i am showing single post per page for the category but the_content function in my loop returning content of only first page for a post which was divided into pages using <!--nextpage--> tag.
Need you help to find out a way for displaying complete content of a post which was splitted in pages using page break tag.

You can get complete content of post using code below.
Retrieves post data using get_post function.
$post_object = get_post($post_id); //
/// Now, you have post object and can get complete post content from post object
$post_content = $post_object->post_content;
use do_shortcode or apply_filters to properly format your post content.
echo do_shortcode($post_content);

Related

How to target a single viewed post page on Wordpress?

I want to add an HTML tag if the page viewed is a 'viewed post page'.
For example, if I have a blog and I am viewing the list of posts - after I click on the post and see the whole text and see all the post - I want to echo an HTML text.
I tried using if ( !is_single ){}...
I tried using if ( !is_single($post) ){}..
I tried using if ( !is_singular ){}
The only thing I find on Google is how to target specific posts.
I went through the conditional tags too: https://codex.wordpress.org/Conditional_Tags
I didn't find what I'm looking for.

WordPress: display full post AND excerpts on one page

Is there a way my category archive display both full posts and excerpts?
What I want is the first two or three latest posts display as full content posts, and all the others as excerpts with just title and a read more button. These are displayed on one page. I am currently using a category archive, on the twentyfifteen theme.
I know I can set a page to either display full or just excerpts, but not a combination. Is this possible?
Thanks!
You can get these in your wordpress loop on page or post.
<?php
$content = get_content($post->ID); //full content of post
$excerpt = substr($content,0,150); //you can limit charaacter like 150
?>

WordPress Custom Fields get post from page

I'm working on a WordPress website and i have a little problem with the custom fields plugin. I'm familiar with plugin and worked with it few times before.
I created a custom field for posts and a custom field for pages.
When i try to get the page's custom field i get it with no problem.
The page has global $post on top and i do get a different $post->ID
for each post loaded.
$pageMonth = get_field('page-month');
But when i try to get the post's field i get nothing.. I also tried it through
the post's loop with $post->ID
<?php $postMonth = get_field('post-month', $post->ID); ?>
I checked myself few times, the custom field names are fine and i did
attached the post and the page to their custom fields and everything..

Dropdown of existing posts in a metabox

I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!

WordPress - how to insert html code selectively in posts

I want to display custom html code when a post is rendered (so not when is inserted into the database).
I currently do this with add_filter('the_content', 'my_custom_method'). The only problem is that I want this do be displayed only inside the post (when is viewed in its own page), not when all posts are rendered .
I banged my head against the wall, but couldn't find any method to tell me if i'm currently inside an individual post or not (this has to work for every url rewriting possible, so i can't rely on url)
Is there such a method? I believe it should be, but i can't find it. Thanks.
the function for checking if the post is in its own page is is_single()
add_filter('the_content', 'my_custom_method');
function my_custom_method(){
if(is_single()){
//code for your custom html code
}
}
the function is_single() checks if the page being rendered is a single page or not.
The easiest way to do this would be to modify your templates. Wordpress template sets should have a file named single.php (inside wp-content/themes/<theme name>). This is the page that gets rendered when you are viewing the page for a single post.
You could edit this file and insert whatever you needed to for the posts there.

Resources