What hook should I use if I want to trigger an event after post is published?

Solved7.26K viewsWordPress
0

I’m working on an extension and would like to confirm the correct hook for triggering an event after a post has been published? Curious about both question and answer custom post types.

1

It goes like this:

process_form()
process_ask_form()
    wp_insert_post()
add_action( ‘save_post’, ‘action_on_new_post’)
action_on_new_post()
    do_action( ‘ap_processed_new_question’)
add_action( ‘ap_processed_new_question’, ‘after_new_question’)
after_new_question()
    do_action( ‘ap_after_new_question’) // <---
add_action( ‘ap_after_new_question’, ‘new_question’ )
new_question()
add_action( ‘ap_after_new_question’, ‘new_question’ ); //reputation
new_question() //reputation

Really simple!

Is there a software in PHP world that would build such maps/stacks for me automatically? Maybe some easy real time php debugger?

@Dima…Greetings please. How do I do this. I want to add an item before “Title” in the ask a question page. The item I want to add is (Note: bla bla bla some caveat emptors here). I hope you understand this. I know that there is a second tap (How to Ask) but I don’t want to use that. Help please!!! And don’t forget that am a newbie!!! So explain your steps or the steps I should take to make it work. Thanks.

Hi @siconet. I’m not an employee here, just answering curious questions as a part of my training in PHP/Wordpress/Anspress. I think you should try asking general public here, not just me.

If you want to add a static text to one of pages, you just override that page’s template (copy it to your theme’s /anspress/ folder), add your text in your template.

In case you want to show your text above title which is rendered in base page template, you could use CSS to make this text appear where you want it, or you may edit base template to conditionally display that text, or you could embed widgets code in there, and use a conditional widget.

Proper solution would be to not output any text above the page title. Because, it’s a title. It should go first.

@Dima…thanks. Asked you specifically because you respond, which makes things flow faster for some of us newbies. Will direct questions to general house next time. Will try your suggestions above and revert. Thanks.

You are viewing 1 out of 3 answers, click here to view all answers.