WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Weird add_action+wp_insert_post (5 posts)

  1. edobejar
    Member
    Posted 3 years ago #

    Hi,

    I'm using a template that uses the wp_insert_post() function to publish posts from outside the WordPress administrator. Now I'm creating a plugin to send an email to users when a new post is published (actually users who belong to a specific usergroup). From what I understand, I should use the wp_insert_post action hook so the plugin runs everytime a new post is inserted with that function, but somehow it's not working.

    I'm using
    add_action('wp_insert_post','function_name');
    at the beginning of the plugin but it does not work. No error. It's just not being triggered.

    When I try
    add_action('publish_post','function_name');
    and I publish a post from the WordPress administrator, plugin works fine and emails are sent. When using this, also plugin isn't triggered from outside the administrator.

    Any idea on what could be wrong? Which action hook should I try too?

    Thank you for your help.

  2. Jerry
    Member
    Posted 3 years ago #

    If I'm getting this right, you've only tried the action hook publish_post by posting directly from the admin, how about remotely, via your plugin or whatever?

  3. edobejar
    Member
    Posted 3 years ago #

    Hi, thank you for replying. Yes, when using publish_post I tried also posting from the template, that is outside the admin and plugin isn't triggered.

  4. edobejar
    Member
    Posted 3 years ago #

    Here's additional info regarding this problem:

    - Template uses wp_insert_post($post) to publish each new post.
    - The plugin I created uses add_action('publish_post','function_name') as hook.
    - Plugin should work each time a new post is published from the template, but it's not working. Though, if I publish a new post from the admin, it works.
    - I also tested add_action('wp_insert_post','function_name') with the same result.

    Any other action hook I should try to make the plugin work?

    Thanks

  5. edobejar
    Member
    Posted 3 years ago #

    For the record, I fixed this. I found that add_action was actually being triggered with publish_post and the problem was using other functions outside the wordpress loop that were not getting the data they were supposed to get.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic