Instead of using get_posts
, which you would use if you wanted to retrieve multiple posts in a loop, you should use get_post
, which only retrieves one post by an ID. There is also a built-in excerpt so you might want to go with retrieving post_excerpt
.
function get_the_excerpt_id($post_id) {
$find = get_post($post_id);
$excerpt = $find->post_excerpt;
$excerpt = strip_tags($excerpt);
$output = substr($excerpt, 0, 100);
return $output;
}
Related Posts:
- setup_postdata() does not seem to be working?
- Regenerate Slugs From Title of Posts
- Why get_posts are only showing five posts (retrieved by assigning a category to them?
- WordPress get_posts by category
- Alternative to get_posts() due to multithreading cache crash
- How to restore deleted pages/posts?
- get posts based on meta value of the author
- date_query not returning some posts in date range
- How do you get posts by meta_query using the JSON API plugin?
- Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?
- Query posts ordering by title, but ignore ” and special characters
- get_posts not honoring post_status
- get_posts only children from certain parents
- get_posts cannot grab from specific category
- Filtering custom post type query
- Display 4 chronological posts starting with a random post
- Allowing SVG uploads in media uploader without plug-in
- get_posts from post x(offset=>x) to end
- With get_posts(), how can I put a category as a variable
- Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured
- How do I combine these 2 queries
- Unable to get_the_content(); of a post in WordPress via AJAX
- Increase the page size of the WordPress REST API
- Cache Get_posts
- get_posts() returns all posts rather than the ones specified with ‘post_author’ =>
- Query random post from different categories
- get_posts() excluding all children of a specific post/page
- `get_posts()` ignore my custom post
- excluding current post from get_posts
- How to query posts to include specific pages of one post type, and all pages of another post type?
- Only retrieve posts where post_excerpt has been filled out
- Can I use numberposts=-1 and offset together when using get_posts()?
- Ordering posts in get_posts
- Automatically wrap multiple images in div
- How can I add text to all posts/pages/categories/homepage etc
- Get posts inside Get terms problem
- Page displays content from different query?
- Error when adding excerpt to the content through functions.php
- Create a new query in function.php to filter blog posts
- show first 3 thumbnails of posts in different sizes [closed]
- Ho to add get_relative_date and post_except to this get_latest_post query?
- get_posts() not working in functions.php
- Getting only a specific post type with get_post?
- Display post details by post ID
- What is the p parameter in a get_posts() parameter array?
- Memory issue with get_posts( ) function
- get_posts() using an array of post ids [closed]
- How can I show the author’s latest post with title?
- get the post_date of ID
- If user is logged-in display/hide something
- Get posts in between specific ID’s
- Test if a post exists by category and date
- Don’t submit post if post title exists
- Turn get_posts as string into an array for use in theme admin options
- The_excerpt() doesn’t parse – how to change that?
- Why would get_posts be ignoring posts with 2-digit ids?
- Not able to get random post
- Order custom post type by custom field (created by PODS) via PHP
- get_posts returns all posts
- Override Blog pages show at most with get_posts
- Is it possible to use array_walk() to append terms to an array of posts?
- Related Posts function not working
- the_content() Not Grabbing All Content
- ‘child_of’ in get_posts not working
- How to use get_posts() function in functions.php
- Fetching All Posts (200+) in a Category – Performance Issues?
- Can’t get Category link inside get_posts
- How do I get only a certain number of images from a post (minus the featured image)?
- Yet another get_posts() in explicitly defined order problem
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Sort get_children by menu_order
- Working with get_posts parameters/arrays/strings
- Getting post by specific date in Advance Custom Field
- List random posts on single page in the current category
- Divide the list into two columns (get_posts)
- Using post title as term in query, only working with single word titles
- the_excerpt function not showing image
- WordPress echoing content in seemingly random place
- How to add content above footer in posts from specific category
- How to use get_posts to filter against a single post id?
- Why set cookie from URL parameter doesnt work all the time?
- How to get a custom post with the largest ID (not the last post by date)
- Is there a way to extract a single post better than using get_posts()?
- Exclude admins from query get posts
- Array merging multiple get_posts throwing Undefined offset error
- Custom Category widget
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- Using get_posts, I need to use a combination of OR & AND relations
- Remove Featured Images from Posts Older Than a Certain Date
- Regex works in regexr, but not if I filter content [closed]
- get_posts array ‘between’ not behaving
- How to Retrieve Post ID of another page
- Problem in shortcode outputting content
- Why WP_Query in functions.php is not working when get_posts works?
- Overwriting a Shortcode
- Show posts in a list separated by day
- How to use wp_editor(); in functions.php then retrieve content in the template
- Sorting posts by specific order
- Single dash converted to double dash
- Integrating custom API for post content into Admin interface & Public Website [closed]