WordPress.org

Ready to get started?Download WordPress

Forums

Automatic category creation and category is post title (2 posts)

  1. chizet
    Member
    Posted 3 years ago #

    Been racking my brain (and google) trying to figure this out.

    What I want is for every post to automatically create a category that matches the post title. So, if I create a post title "Look at me" I want a category to be automatically created also called "Look at me".

    I've tried using wp_set_object_terms like so:

    $cat_ids = array(9992);
    wp_set_object_terms( $post->ID, $cat_ids, echo get_the_title() );

    but no dice.

    Any ideas??

  2. chizet
    Member
    Posted 3 years ago #

    I've gotten relativly close:

    $post_id = 1;
    $cat = get_the_title($post_id);
    
    // Adding category to the post
    wp_set_object_terms( $post_id,  array("$cat"), 'category');

    Now I just need to replace the specific post ID with the current post's ID - is that possible?

Topic Closed

This topic has been closed to new replies.

About this Topic