I have used function to extract data inside figcaption tags, and $position is stand for the index of the current image.
function getImageCaption($postID, $position){
$post_id = $postID;
// get the post object
$post = get_post( $post_id );
// we need just the content
$content = $post->post_content;
// we need a expression to match things
$regex = '/<figcaption>(.*)<\/figcaption>/';
// we want all matches
preg_match_all( $regex, $content, $matches );
// reversing the matches array
$matches = array_reverse($matches);
// we've reversed the array, so index 0 returns the result
foreach ($matches as $key => $value) {
return $value[$position];
}
}
Related Posts:
- Disable Attachment Pages Completely
- Display posts by month
- Custom SQL query to get List of posts with featured image url
- get_the_content if it contains multiple lines it results in SyntaxError
- Looking to exclude blog posts from category Previous/Next buttons
- Automatic Excerpt Not Working
- Using a javascript file to access a get posts array
- WP Insert Post function – Insert Post Thumbnail
- How is WordPress manipulating the posts like there are folders?
- Get taxonomy terms only of the WP_Query current posts
- How to get 2 or multiple custom post types in wordpress functions.php
- Trying to make php run in a post
- Remove posts after a given amount of time
- Hide wordpress field if data is empty in post!
- How to show part of the_content?
- Unreadable pagination
- How to set a min number of words for a blog post
- Get post id in a function when edit/add a post
- Which hook/action will help me solve my problem?
- Open post-content in archive page in a Modal box with bootstrap
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Get children post mime type using parent post_ID wp_post
- 404 error when I acess the second page of post-type
- Which PHP page is the Default Posts Page
- WP Insert Post and then go to post
- Copy taxonomy terms from one post to another programmatically
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Parse error: syntax error, unexpected end of file
- Automatically add images to a menu
- Load Posts on Click via Ajax into a DIV
- How to catch wordpress post ID when it’s published
- Store metakey value as an array
- Only show first image in foreach loop
- WordPress upload file size error even after raising php limits
- create front-end users post list by specific category
- show recent posts php code error?
- Error display post thumbnails for previous and next post
- Post to WordPress from another Server via PHP
- form $_post action value gets truncated after it passes through two forms
- Wrap posts p tags in div
- Wp Query : Order by distance lat,lon
- remove specificly the last tag in all posts
- Add posts to custom table in database instead of wp_posts
- get value from get_post_meta then reuse it in another get_post_meta
- How to show categories and date on posts
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- WordPress Post Block Element not properly parsed with the_content filter
- Filter wordpress posts without searching the keywords in the post content
- Build A Custom SQL Query for WordPress Search
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- How to Send Pingbacks for all Posts in WordPress?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- WordPress sorting posts by date and title using a dropdown
- Query on a repeater date (acf)
- Trying to get post ID outside loop on blog page
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- Check the database for a postmeta field
- Send POST request to Flask app from functions.php file
- Get list of posts from attachment
- How to pull date/time in french format for wordpress post?
- Send Notification after post published was working but stopped after the last WP update
- How to display last whole post on the homepage
- How to insert text into post based on category – via single.php file
- When working with a post, almost all wp_postmeta are deleted
- WordPress Single Post Pagination Numbered and Navigational
- Let user select the number of posts shown per page jquery error
- Add wp posts to cutom masonry grid
- Displaying POST content with HTML tags and all
- Generate random access token to a post page
- Displaying 3 Category Posts differently
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Get posts associated with media attachment
- ‘posts_per_page’ in costum page type
- Can’t put a hyperlink on Featured Post’s Image
- Passed variable gets undefined variable error on insert on next page
- WordPress get_post_meta issue
- List of child pages fetch next results at link click
- Automatically create a loop for post ID
- Why does WP_Query show only the same post even with different categories and endwhile?
- Display pages from specific page template
- Query posts by custom fields (object post)
- How to modify this function to exclude also the post belonging to a specific category?
- How to display the date under the post title?
- Excerpt all post content Content Same Size without word cutting off
- Set post to draft if matching word is found in the post
- Add multiple HTML attributes to an Elementor button
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- Display posts based on the selected category when no subcategory is chosen