Your code has many errors:-
$thumbsisn’t used anywhere.$img_url = $thumb['url'];undefined variableif(is_array($thumb) && $img_url)alwaysfalsebecause of second point.$search_data = [];should be outside of loop.
Check the correct part of code
$search_data = [];
if($query->have_posts()):
while($query->have_posts()):
$query->the_post();
$img_url = get_the_post_thumbnail_url();
if(!empty($img_url)){
$search_data[] = array(
'name' => get_the_title(),
'thumb' => $img_url,
'desc' => get_the_content()
);
}
endwhile;
endif;
NOTE:
get_the_post_thumbnail_url()is only available from WordPress
4.4
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Remove option to allow trackbacks/pingbacks from post page options
- Alter query on edit.php
- Permanently remove first image from posts
- Handling an Ajax form submit
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- New Plugin Review
- Use template for posts with a particular category grandparent
- Automatically generate Post/Page from searched Database item?
- Styling images coming from another blog
- “before delete post” action fire when the post is updated?
- Hide post if matches current month and year
- Automatically add custom CSS to new posts using a category template
- How Display Posts on category
- Query all posts of a custom taxonomy term
- Retrieving Author ID in wp-admin area
- Displaying the last post on static homepage
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- Best practice for migration friendly images in posts/pages?
- 200 Rewrite blog post links
- Automatically create child pages and grandchild pages when saving a (parent) page
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Second transition_post_status hook fired instead of the first
- How can I add extra word in permalink when someone click download button?
- remove post that has no content
- Custom posts in different columns style
- How to show only subcategories in parent category not parent category?
- 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
- 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
- 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
- How to get post titles by post ID and integrate with my code?
- Trying to get post ID outside loop on blog page
- Infinite looping next post link within a certain category on a post
- 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
- Send Notification after post published was working but stopped after the last WP update
- How to use a PHP file to control the content of a blog post
- When working with a post, almost all wp_postmeta are deleted
- Displaying POST content with HTML tags and all
- Generate random access token to a post page
- Pagination in WP Queries
- Using Tag Groups: Displaying groups and adjacent tags of current post
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Display 6 most recent post on homepage?
- Only Get A Certain Number of Posts From WP_Query
- Apply filters when loading post via ajax
- Get posts associated with media attachment
- Can’t put a hyperlink on Featured Post’s Image
- How to call post title and post summary to other part of site?
- Published custom posts missing
- WordPress get_post_meta issue
- Automatically create a loop for post ID
- Display pages from specific page template
- Add Custom Post Type on the Fly or create an array
- WordPress article with 50 000 words loading slow – 100% cpu
- Display post of specific category on page
- Query posts by custom fields (object post)
- 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
- WooCommerce: write featured image dimensions to custom fields in product’
- transition_post_status hook, works – but not if the post is new
- How to get ACF field to show up on all posts on front end?
- Category Attachment Pagination 404 Error on 2nd Page
- Warning: Undefined variable $post_id