Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a Bakery page. Every time I add a child page such as cakes, I would like to add the page title cakes to a custom taxnomy. I also want to add this child page to a menu which displays these child pages.

I have found out that I need to hook into the new_page. So something like this,

function($page_id){
    check if this page is type of page and parent_page is Bakery Page's ID

    If yes, then add this page to menu which displays the child pages. I suppose I need the ID of the menu but I do not know how to find it, not even to hard code it.

    Lastly I want to add the title of this page to a custom taxonomy.
}

Can you help?

share|improve this question
    
That hook won't work in this case, and it'd have to be add_action('new_auto-draft', 'callback');, and kind of useless for your need. You are asking two very different questions (add-to-menu & create-custom-taxonomy). For the second one research this. I'm voting to close the Q, and suggest you to refactor it focusing in one item, and putting more research in it. And opening a new one for the other. .... Nice trick, to put more text into pseudo-code :) –  brasofilo Dec 2 '12 at 2:43

1 Answer 1

up vote 1 down vote accepted

I agree with @brasofilo that this is two very different questions, but I think we can answer both here.

1. Automatically add child pages of A to custom taxonomy B's term C.

We'll add the term 'yummy' in the custom taxonomy 'food-adjective' to all child pages of page ID 123 when they're published. You can add this to your theme's functions.php file.

/**
 * Automatically add a custom taxonomy term to child pages of page 123 on publish
 *
 * @param int $post_id 
 * @param object $post The new post
 * @return void
 */
function wpse_74605_auto_tax( $post_id, $post ) {
    if ( 123 === $post->post_parent ) {
        wp_set_post_terms( $post_id, 'yummy', 'food-adjective', true );
    }
}
add_action( 'publish_page', 'wpse_74605_auto_tax', 10, 2 );

2. Automatically add child pages to menu

This is covered in a number of plugins, so I won't reinvent the wheel here. I'd recommend Viper007bond's Add Descendants as Submenu Items.

share|improve this answer
    
Thanks a lot. very helpful –  Lucky Luke Dec 2 '12 at 20:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.