Articles of save post

Set default Custom Post Meta Value

I’ve tried almost anything and just can’t get this to work. I have a custom post type with a custom meta field and I want a default value to be added on when the Publish/Update/Save button is pressed. I tried all kind of hooks wp_insert_post, save_post, edit_post.. add_action(‘save_post_post_type’, ‘set_default_meta’, 10, 3); And my function is: […]

Checked() function on a multidimensional array

I am generating checkboxes dynamically on one of the option pages. This the code that I’m using to create multiple checkboxes: <?php foreach($shopCategories as $shopCategory) { ?> <input type=”checkbox” value=”<?php echo $shopCategory->term_id; ?>” name=”term_meta[ss_aff_categories][]” <?php checked($term_meta[‘ss_aff_categories’], $shopCategory->term_id, true) ?>> <?php echo $shopCategory->name; ?><br/> <?php } ?> The problem is that with thechecked() function in place […]

Metabox of one post influence setting on other

This great answer by David Gard allowed me to have a metabox sticky (checkbox) for posts that could only be set (checked) on one posts in the loop at a time. If post A has that meta box checked, then B, C … Z can’t have it checked. In order to be able to check […]

Cant't delete my custom posts

I added this code in function.php in order to replace post_date with an ACF field every time i update mu custom post. It works perfectly ! BUT Now in WP admin i can’t delete (to trash) any custom post in the list Could someone help me please ? thanks add_action(‘save_post’, ‘change_content’); global $post; global $wpdb; […]

duplicate entries in database while using save_post or wp_insert_post

Here is what I am trying to do – I have created a custom table in the database and I am trying to enter data into it everytime a post is created. The database-entry needs to happen ONCE AND ONLY WHEN A NEW POST IS CREATED. NOT on post-update, revision, status-change etc. FYI, new posts […]

Help using acf/save_post hook to connect to Untappd API and update_field

What I am trying to accomplish is: when I save a or update a post, I want to access the Untappd API, grab a link to an image, and update an ACF field with that link. I am attempting to use the acf/save_post hook to accomplish this. Here is what I have so far: function […]

Returning ACF custom field from publish_post

I’m trying to return a custom field as soon as a post gets published. I’m using the publish_post (or {status}_{post_type}) action, but it looks like the custom fields are created after the hook. My code in functions.php: function create_recurring_posts( $ID, $post ) { logMe(print_r(get_post_custom($ID), true)); } add_action( ‘publish_profile’, ‘create_recurring_posts’, 10, 2 ); The logMe() function […]

Change auto post title generation according to different post properties

I have the following snippet that allows me to auto generate the post title. I’d like to change the $post_type of the ‘post_title’ => $post_type . ‘ Job #’ . $post_id line to some other post property like post_date and post_author. function save_post_func_2134( $post_id ) { $post_type = ‘post’; //Change your post_type here if ( […]

Save post in another table

I have problem in post date, Now when i add post at 17/1/2016 and modify this post to 18/1/2016. Now the old date are delete from table in database. So, I need to save old date in another table, when i add new post. How can do that ?

Updating user meta on save post

I have a custom post type called ‘programmes’ that details seminar information. Using a form visitors to the site can signup to a specific ‘programme’, once they have completed the form a new user is created with the following user meta: programme_id – the post ID of the ‘programme’ registered on programme_name – the title […]