get_post_meta not working with variable as a post_id for dynamically get the postid
You can try to add global $post; on top of your code. But it depends on where the function is called.
You can try to add global $post; on top of your code. But it depends on where the function is called.
If I understood you correctly, you want to prevent users from selecting a radio option, which have been already selected on another post, when the user is adding a new post, right? I think you need to first check if the user is on the “add new” page in your metabox. You can do that … Read more
What your are doing is that you are looping over an array of post objects. The get_posts() function returns objects, not ID’s. So what you will have to do is either use $post_id->ID or setup_postdata( $post_id ) and then use get_the_ID(). Might wanna rename $post_id to $post_object to avoid confusion.
It turns out the latest Advanced Custom Fields update (from version 5.6.0 on) removes the core custom fields metaboxes by default. The way to restore it was to add a filter in functions.php: add_filter(‘acf/settings/remove_wp_meta_box’, ‘__return_false’);
I solved: add_action(‘save_post_product’, ‘update_post_meta_subito’, 10, 3 ); function update_post_meta_subito($post_id){ $prova_termine=”inzaghi”; $term_taxonomy_ids = wp_set_object_terms( $post_id, $prova_termine, ‘pa_autore’, true ); $thedata = Array( ‘pa_autore’=>Array( ‘name’=>’pa_autore’, ‘value’=>$prova_termine, ‘is_visible’ => ‘1’, ‘is_variation’ => ‘1’, ‘is_taxonomy’ => ‘1’ ), ); update_post_meta( $post_id, ‘_product_attributes’,$thedata); }
You could do it with a meta query $current_post_id = ‘YOUR_POST_ID’; $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘_crosssell_ids’, ‘value’ => $current_post_id, ‘compare’ => ‘LIKE’ ) ) ); $query = new WP_Query($args); if($query->have_posts()){ while($query->have_posts()): $query->the_post(); $product = wc_get_product(get_the_ID()); // Do what you want with the product. endwhile; … Read more
Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
How do I get all authors posts of a custom post type outside loop
Get post content before rendering
I continued to research my issue and ended up finding the solution here: I need query_posts() to order results first by a meta value and then by post ID Basically, it seems the WordPress orderby is screwed. When I examined the SQL it was producing the orderby looked like this: ORDER BY wppc_postmeta.meta_value+0 DESC Which … Read more