Event(hook) save_post
-
I have such code in functions.php
add_action( 'save_post', 'add_review_db', 10, 3 ); function add_review_db( $post_ID, $post, $update ) { //my code }If I added new post from admin panel, this function executing. But if I submit form
[user-submitted-posts]functionadd_review_dbdoes not executing, why? And how I can use hooks in with this plugin?
-
Glad to help. Using the example provided on the
save_postdocumentation:function my_project_updated_send_email($post_id) { // add functionality here } add_action('save_post', 'my_project_updated_send_email');I submitted a post via the USP shortcode and the
save_posthook fired as excpected. So I am not sure what might be happening in your specific case, but it could be something like a plugin or theme that is interfering. Also may want to check the syntax your code is using, compared to the Codex example (looks a bit different).Let me know if I can provide any further infos, glad to help however possible.
Thank You for answer. But I still have a problem. As I write, hook
save_postworking without plugin USP, but when post added by plugin USP(form), hooksave_postdoes not working. I can conclude that problem in plugin USP.I found some problem. In my function I have check
if ($_POST["post_type"] == "reviews"){ //code }and I think
$_POSTorpost_typedoes not send by USP. Is it true? How I can checkpost_typein my way?I’m not sure, but I can tell you that, on default WordPress installation, the
save_posthook is firing as expected. If that is not happening in your case, you will need to troubleshoot your plugins and theme. Or, if the site is live, you can set up a 5-minute installation of WP, leave everything at defaults (settings, plugins and theme), and then try USP again. You will find thatsave_postfires as expected. And like I said, another thing that I recommend checking is the syntax of your function where it calls thesave_posthook; the syntax looks incorrect, based on the example provided in the WP documentation.Updated to add: you are correct, the plugin does not use
$_POST['post_type']anywhere, but you can check the plugin option,$usp_options['usp_post_type'], to get the current post type.-
This reply was modified 7 years, 10 months ago by
Jeff Starr. Reason: adds info
okay. and what about meta fields, I tried such code
$username = get_post_meta($post_ID,'user-submitted-name',true);
whereinput name="user-submitted-name"
http://prntscr.com/iwr5pg
but it is empty it functionThe best way to get the names of attached custom fields (meta) is to take a look at a submitted post (via the “Custom Fields” meta box). What you see in the form/HTML is different than the actual custom fields that get added. For example,
user-submit-nameresults inuser_submit_nameas the custom field name.look “Custom fileds”, there are http://prntscr.com/iwrgly
user_submit_nameand I change code
$username = get_post_meta($post_ID,'user_submit_name',true);
it still emptyWow that is weird.. are you sure the Post ID is correct? That is WP template tag, not USP, so you may want to ask the WP core team support if it’s not working.
I want to clarify – my code working with system adding post(add from admin panel), there allright. But problems only in adding posts from USP.
Yes I understand, please let me know how I can help you.
It will be good, if you can tell me, why this plugin does not send meta fields in the same view/array/variables –
get_post_meta($post_ID,'user_submit_name',true)as it do it system of WordPressBecause the variables are modified within the plugin code.
ok, I need custom field
user_submit_name, it modified by plugin? how I can get name of modified name of custom field?You can either grab the custom field:
user_submit_name, or you can grab the POST variable:$_POST['user-submitted-name']thank you, that what I need.
P.S.
Maybe I am wrong, but I think, your plugin does not send right names of custom fields or some thing else. It does not work with functionget_post_meta(); -
This reply was modified 7 years, 10 months ago by
The topic ‘Event(hook) save_post’ is closed to new replies.