WordPress Codesnippets

Programmatically upload image

				
					
				
			

This code creates a WordPress image media object using a provided image file. It stores the image file name and path in $image_name and $image_path variables, respectively. It then creates an array ($image_data) with the file name, type, temporary location, error value and size values. Finally, it creates the image media object using the media_handle_sideload() function and returns the image ID or an error object.

Was this code snippet helpful?
YesNo

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »