How to add image attachment to post from a single meta key (Woocommerce)

I got it now using the following code: //featured image from postmeta function postmeta_img_update() { global $post; // If Custom Post Meta Field for a Image/Thumnail Exists if( get_post_meta($post->ID, “_image”, true): // Get Image Location and File Extention $img = get_post_meta($post->ID, “_image”, true); $ext = substr(strrchr($img,’.’),1); // WordPress Upload Directory to Copy to (must be … Read more

dynamically add a custom field or metabox to custom post type [duplicate]

To add a metabox to a post type car use the proper hook: add_action( ‘add_meta_boxes_car’, ‘register_car_metabox’ ); function register_car_metabox() { add_meta_box( ‘car-data’, ‘Car data’, ‘car_metabox_callback’, NULL, ‘normal’, ‘default’ ); } The content will be created in your callback: function car_metabox_callback() { # get post meta and print input fields }

How to Display pages with a Custom Fields in one page

You can get pages with get_pages(), in the arguments you can provide a search query for post_meta, like for example: $args = array( ‘post_type’ => ‘page’, ‘meta_key’ => ‘section’, ‘meta_query’ => array( array( ‘key’ => ‘section’ ‘value’ => ‘surgery’ // here you could place get_the_title() ‘compare’ => ‘=’ ) ) ); $pages = get_pages( $args … Read more

Better Method for Multiple Meta Boxes

I’ve sort of done this with using the same function to save the meta on the post screen and also on the quickedit. In your case I think you need to add an or clause to your nonce validation. if (!wp_verify_nonce($_POST[‘home_meta_box_nonce’], basename(__FILE__))) return; as if (!wp_verify_nonce($_POST[‘home_meta_box_nonce’], basename(__FILE__)) || !wp_verify_nonce($_POST[‘home_meta_box_left_nonce’], basename(__FILE__)) ) return; Then you could … Read more

Checkboxes in registration form

Short of creating a custom registration page, there are not much hooks that can be used to add custom fields to the default form. I tried once (with register_form hook) and only default fields (description, website, etc) were successfully recognized and saved. Found this Q&A that has a workaround: Adding extra info via GET while … Read more

WP_Query orderby not working with meta_value_num and menu_order

Found an answer to this. Somehow WordPress’ own orderby isn’t fully functional when trying to order by multiple values. I solved this by changing WP_Query to SQL Query, and including second DESC after _postmeta.meta_value+0 SELECT XXX_posts.* FROM XXX_posts INNER JOIN XXX_postmeta ON (XXX_posts.ID = XXX_postmeta.post_id) WHERE 1=1 AND XXX_posts.post_type=”sidebar_element” AND (XXX_posts.post_status=”publish”) AND (XXX_postmeta.meta_key = ‘sidebar_element_meta_alignment’ … Read more