How to save multiple values in custom post type from front end to back end

wp_insert_uses (trac) the following loop to handle meta_input, if ( ! empty( $postarr[‘meta_input’] ) ) { foreach ( $postarr[‘meta_input’] as $field => $value ) { update_post_meta( $post_ID, $field, $value ); } } So if you change meta_input in your new post args to be like this, ‘meta_input’ => array( ‘invocies’ => array( ‘service’ => $_POST[‘service’], … Read more

How to show metabox on page if it is using a template

Use the page-specific meta box hook & accept the $post object that’s passed to it – then you can check if it currently has a page template of sky-template.php. add_action( ‘add_meta_boxes_page’, function ( $post ) { if ( $post->_wp_page_template === ‘sky-template.php’ ) { add_meta_box( ‘sky_page_excerpt’, ‘SkyScraper Page Excerpt and Links’, ‘sky_page_excerpts’, ‘page’, ‘advanced’, ‘high’ ); … Read more

How to load page template according to the Searched Page

Just use wp_get_referer(), and a few other functions to get the simple name of the referring page, e.g. if (basename(parse_url(wp_get_referer(), PHP_URL_PATH)) == ‘my-search-page’) { (Or you could use string searching or matching instead of parse_urland basename). (Also note wp_get_referer is deliberately misspelled. It originates in a misspelling in one of the web standards) Addendum Might … Read more