if condition from post_meta not working in save_post
if condition from post_meta not working in save_post
if condition from post_meta not working in save_post
I have made some changes: SELECT wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id INNER JOIN wp_icl_translations t ON wp_posts.ID = t.element_id WHERE 1=1 AND t.element_type = CONCAT(‘post_’, wp_posts.post_type) AND wp_postmeta.meta_key = ‘post_views_count’ AND wp_posts.post_type=”post” AND wp_posts.post_status=”publish” AND ( (t.language_code=”fr” AND wp_posts.post_type IN (‘post’,’page’,’attachment’,’grille’,’podcast’,’equipe’)) OR wp_posts.post_type NOT IN (‘post’,’page’,’attachment’,’grille’,’podcast’,’equipe’) ) GROUP BY wp_posts.ID … Read more
get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
This worked for me as long as it’s run only on the appropriate query. The key is MySQL’s FIELD() function, which lets you specify an arbitrary ordering. add_action( ‘pre_get_posts’, ‘add_match_times_to_query’ ); function add_match_times_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘meta_query’, array( ‘match_time’ => array( ‘key’ => ‘match_time’, ‘compare’ => ‘EXISTS’, … Read more
I you need to use update_post_meta($post_id,’your_meta_key’,’your_meta_value’); or you can save in new variable like $city_value = $_POST[‘city_field’]; then code will be update_post_meta($post_id,’city_field’,$city_value);
Does this meta field store some other post’s ID, of which you want to retrieve the post name? If so, try this <?php global $post; $customlink = get_post_meta( $post->ID, ‘clink’, true ); echo get_post_field( ‘post_name’, $customlink ); ?>
Don’t put your variables in single quotes. This: if(isset($submit)){ $args = array( ‘numberposts’ => 10, ‘meta_key’ => ‘$filter’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘post_type’ => ‘things’, ‘post_status’ => ‘publish’ ); $mystuff = get_posts( $args ); $name = $filter ; } Should be this: if(isset($submit)){ $args = array( ‘numberposts’ => 10, ‘meta_key’ => $filter, ‘orderby’ … Read more
I was having some issues like yours. It was because it was on a page template with a query above it. All I had to do was reset the query.
A quick google search would have directed you to this page: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
You have to use update_post_meta insted of add_post_meta if(isset($_POST[‘posrav’])) { if($_POST[‘posrav’]!=””) { $posrav=get_post_meta($post->ID,’pcom’,true); $posrav=$_POST[‘posrav’]; update_post_meta($post->ID,’pcom’,$posrav); } }