WordPress custom post type
change your $args array to the following $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘productcategories’, ‘terms’ => $term->name, ‘field’ => ‘name’ ), ), );
change your $args array to the following $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘productcategories’, ‘terms’ => $term->name, ‘field’ => ‘name’ ), ), );
Problem with ‘save_post’ hook not running
Sorting Posts with meta value not working
Performace on 1 million plus meta fields vs 1 field with 1 million multi array
meta query always fails even if data is correct
This is the way I always do it… add_action( ‘save_post’, ‘header_setting_generate’, 99 ); function header_setting_generate($post_id) { global $post; if(isset($_POST[‘post_type’]) && ($_POST[‘post_type’] == “page”)){ $value = array( ‘header-settings’ => ‘page-data’, ); update_post_meta( $post_id, ‘_skoty-page-header-settings’, $value); } } After inserting this code, go to “Pages”, Select All, click Bulk Edit, Change status to “Published” just to trigger … Read more
Seems I have an answer – it was how the SQL statement was setup. $where .= ” OR (( $wpdb->postmeta.meta_key = ‘$meta_key’ AND (UPPER($wpdb->postmeta.meta_value) LIKE ‘%$meta_value%’) ))”; Now is the field has the string “Whistler Bike Park, Canada” but the user only searches for “Whistler”, I get the post/s returned that I expect.
update_post_meta returning false when called during init
You need to escape data while displaying also. Use esc_attr in your case. Try this: <input type=”text” name=”field_name” value=”<?php echo (!empty($field)) ? esc_attr( $field ) : ”; ?>” /> Check this for full documentation – https://codex.wordpress.org/Data_Validation
You can not put condition in callback function as it will display the meta box without the HTML. Better you can wrap add_meta_box() in if condition. If you are on post edit screen you can get the post id in this way. $post_id = false; if (!empty($_POST[‘post_ID’])) { $post_id = $_POST[‘post_ID’]; } else if (!empty($_GET[‘post’])) … Read more