Yes, it is possible, WordPress does not have an API, but some useful functions.
I would load all your rows into array like
$your_table = ['post_id' => 'image', 'post_id' => 'image', …]
Then execute a foreach loop
foreach($your_table as $post_id => $image)
{
//full path to the image
$image_path = _YOUR_FULL_ABSOLUTE_PATH.$image;
/**
* Get an ID of the inserted attachment
* This takes care of resizing image and stuff…
* The fourth param I would sugest you to keep true, since in case of duplicate entry in your table, it will not have been inserted more than once
*/
$featured_image = wp_insert_attachment(array('attachment_meta'), $image_path, $post_id, true);
//assign featured image
add_post_meta($post_id, '_thumbnail_id', $featured_image);
}
‘attachment_meta’ study here
Related Posts:
- Better wordpress attachment query than this
- Return only Count from a wp_query request?
- WP_Query vs get_posts
- Make a WP Query search match exactly the search term
- Query WooCommerce orders where meta data does not exist
- Count the number of images uploded on the website
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- Get attachment by slug
- When should you use wp_reset_postdata vs wp_reset_query?
- Identify which loop you are hooking into; primary or secondary?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- How to get the posts published in last two days using WP_Query?
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- Can not switch the queried post in pre_get_posts hook
- view queries made?
- How to display images in related posts?
- Get the post permalink within the loop but without additional DB query
- List the 5 most recent child pages
- Custom Post order for homepage
- Get image of latest post from taxonomies/categories
- WP Query search for attachments and their exact title
- Page navigation doesn’t show when query category
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Undefined WP_Query::has_posts()?
- Is it possible to dynamically get queried term AND taxonomy?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pull post meta with post_query?
- Query total number of posts
- How to access a query twice in different template files?
- Creating a custom search for a specific post type
- Custom query for sidebar isn’t returning results
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Optional Meta Query
- Set conditional on template based on referring page slug
- Iterating through $wpdb query without using get_results for large query results
- How to use the query hook/filter?
- Query posts intersecting tags and categories
- Order by empty custom field
- No results found from a $wpdb->get_results() query when trying to join more than one meta key query
- How to get a query variable?
- Query Page Content From Theme Options?
- Modify Search Query if original Query gave no results
- Include current post into loop
- Is it possible to query from external database? [duplicate]
- Filter post query to only show direct children of category
- Yoast primary category query modification
- wordpress udpate query not equal to
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Write WP Query that selects posts that are part of the same two categories
- WP_User_Query orderby meta_val_num
- WP_Query custom order and pagination
- Unable to paginate a custom page query
- Include one page/post into query which is already returning posts
- meta_query where the meta value is not the post title
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Pagination of custom page with custom fields query
- Query pages created by deleted users
- Woocommerce Get Orders By Meta Value
- Exclude post from wp_query based on custom field boolean
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Get posts that match defined arrays of tags
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Order posts by tags count?
- Strange results from WP_Query
- Is there a way to control both Order By and Order query parameters from one input field
- I need query_posts() to order results first by a meta value and then by post ID
- How to query 5 users in random who have published more than 10 posts
- return child post if available otherwise parent post
- Search has query that will return no results
- Is my code correct?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- WP Query – Search in title or author_name
- URL to Post Archive of Custom Query
- Meta query doesn’t remove placeholder escape before query
- How can I modify standard search query to include also ACF custom fields values?
- orderby in WP_QUERY – Use the order from the Dashboard
- Random posts in WP_Query when searching by tag
- WP_Query with child element
- Ordering Posts by parent category, name ascending
- WP_Query always returning the last custom post
- How to get query results for the next page
- How to query post into a complex slider
- Loop through multiple custom fields with increasing number
- Combine privileged users array with my current query
- Horizontally paginate through sets of blog posts?
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- meta_query dates from an array
- confirm my booking with phone number
- Pull Instagram images into an existing loop?
- Get WP_Query query after execution?
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- wp_query order by rand is repeating posts
- A Depth Like Parameter For “get_posts”
- Search query alteration not working for meta values
- Advanced Search – Is this possible?