• Resolved max143

    (@max143)


    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] function add_review_db does not executing, why? And how I can use hooks in with this plugin?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Glad to help. Using the example provided on the save_post documentation:

    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_post hook 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.

    Thread Starter max143

    (@max143)

    Thank You for answer. But I still have a problem. As I write, hook save_post working without plugin USP, but when post added by plugin USP(form), hook save_post does not working. I can conclude that problem in plugin USP.

    Thread Starter max143

    (@max143)

    I found some problem. In my function I have check

    if ($_POST["post_type"] == "reviews"){
    //code
    }

    and I think $_POST or post_type does not send by USP. Is it true? How I can check post_type in my way?

    • This reply was modified 7 years ago by max143.
    • This reply was modified 7 years ago by max143.
    • This reply was modified 7 years ago by max143.
    Plugin Author Jeff Starr

    (@specialk)

    I’m not sure, but I can tell you that, on default WordPress installation, the save_post hook 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 that save_post fires as expected. And like I said, another thing that I recommend checking is the syntax of your function where it calls the save_post hook; 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 ago by Jeff Starr. Reason: adds info
    Thread Starter max143

    (@max143)

    okay. and what about meta fields, I tried such code
    $username = get_post_meta($post_ID,'user-submitted-name',true);
    where input name="user-submitted-name"
    https://prntscr.com/iwr5pg
    but it is empty it function

    • This reply was modified 7 years ago by max143.
    • This reply was modified 7 years ago by max143.
    • This reply was modified 7 years ago by max143.
    Plugin Author Jeff Starr

    (@specialk)

    The 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-name results in user_submit_name as the custom field name.

    Thread Starter max143

    (@max143)

    look “Custom fileds”, there are https://prntscr.com/iwrgly user_submit_name and I change code
    $username = get_post_meta($post_ID,'user_submit_name',true);
    it still empty

    Plugin Author Jeff Starr

    (@specialk)

    Wow 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.

    Thread Starter max143

    (@max143)

    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.

    Plugin Author Jeff Starr

    (@specialk)

    Yes I understand, please let me know how I can help you.

    Thread Starter max143

    (@max143)

    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 WordPress

    Plugin Author Jeff Starr

    (@specialk)

    Because the variables are modified within the plugin code.

    Thread Starter max143

    (@max143)

    ok, I need custom field user_submit_name, it modified by plugin? how I can get name of modified name of custom field?

    Plugin Author Jeff Starr

    (@specialk)

    You can either grab the custom field: user_submit_name, or you can grab the POST variable: $_POST['user-submitted-name']

    Thread Starter max143

    (@max143)

    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 function get_post_meta();

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Event(hook) save_post’ is closed to new replies.