Add this to your functions.php in your template folder.
<?php
//Set Default Meta Value
function set_default_meta_new_post($post_ID){
$current_field_value = get_post_meta($post_ID,'YOURMETAKEY',true); //change YOUMETAKEY to a default
$default_meta="100"; //set default value
if ($current_field_value == '' && !wp_is_post_revision($post_ID)){
add_post_meta($post_ID,'YOURMETAKEY',$default_meta,true);
}
return $post_ID;
}
add_action('wp_insert_post','set_default_meta_new_post');
?>
Related Posts:
- How to only display posts whose meta_value field is not empty?
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- WP_Query with meta_value LIKE ‘something%’
- Sorting meta_value as integer doesn’t work
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- Custom WP Query from meta_value stored as serialised array
- meta_query works locally but not on live server
- Ordering Posts Type A by Custom Fields of related Post Type B
- Custom query for sidebar isn’t returning results
- Need wp_query to return all children and grandchildren
- new WP_Query to get max price meta value not working
- Query multiple meta values
- Why isn’t my `meta_query` array functioning properly?
- How to orderby multiple meta fields if some fields are empty
- Meta_query on same meta key, with diffrenct values
- How to extract specific post
- Meta Query relation “AND” then set array accordingly
- Does meta_value (array) work with ‘orderby’?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Create one-use post dynamically, add to main query, do not insert post (user profile view)
- query post by author gender
- Show posts of an advanced search form
- Meta query with compare by more than 2 fields
- Deleting terms from the WordPress wp terms table
- Order (by ASC) posts with meta_key so posts without values are last
- Save queried result into database
- wp_set_object_terms() custom taxonomy not working correctly when using insert post
- WP_Query multiple value not working
- wp_insert_post with ACF Fields and WP Meta Query returns no rows until update
- Gather same custom field values in one value in a select tag with wp_query
- Order posts by more than one variable (meta_key and publish date AND time)
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- how to query for meta_value have array
- Sorting Posts with meta value not working
- Cannot order by in WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Order by meta values
- query_posts, oderby meta_value & print “future” posts
- Get posts by meta value except one post [closed]
- How to `’orderby’ => ‘meta_value_num’` in a series of orderby parameters
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Can I force WP_Query to return no results?
- Can wp_query return posts meta in a single request?
- Using pre_get_posts with WP_Query
- Find out total number of pages in global query on archive page?
- WP_Query + random
- Resetting post data to previous loop in nested loops
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Broken? WP_Query and “attachment” as a post type
- Some doubts about how the main query and the custom query works in this custom theme?
- Order by multiple meta key and meta value [closed]
- Post_count only shows the number of results per page
- Page template query with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- What is appropriate flow for custom data from URL in WP_Query?
- How to display page content in a page template?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to merge two queries together
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- why ignore_sticky_posts in sticky post query
- Wp_redirect and sending variables
- Multiple relationship for multiple tax_query in WP_Query
- How do I get posts that have a thumbnail in WP_Query?
- Multiple WP_Query loops with Pagination
- How do I query for posts by partial meta key?
- Pagination with custom SQL query
- Return only Count from a wp_query request?
- Using a custom WP_Query with get_template_part loop
- Use REGEXP in WP_Query meta_query key
- Why is the loop not empty on some 404s?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP Query Args – Title or Meta Value
- How to query for most viewed posts and show top 5
- WP_Query orderby date not working
- WordPress Pagination Not Working – Always Showing First Pages Content