• I have a site which grab feeds in into category” Germany”

    I want to move/copy Post into different category based on their title like

    If title is
    “Germany Scholarship” This Post move to Germany Category
    “Finland Scholarship” This Post move to Finland Category
    “Phd Scholarship” This Post move to PHD Category.

    Is there any plugin to achieve this ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Give this a try:

    // Add a category to a post based on the title
    // Modify the $title_categories array.  Use one title => one category name
    // Categories MUST exist first and the Post title MUST match exactly.
    function mam_add_category ($post_id = 0) {
       if (!$post_id) return;
       $title_categories = array ( // The titles and the corresponding category name to add
         'Germany Scholarship' => 'Germany',
         'Phd Scholarship' => 'PHD',
       );
       $title = get_the_title($post_id);
       if (key_exists($title,$title_categories)) {
          if ($title_categories[$title] ) {
             $cat_id = get_cat_ID($title_categories[$title]);
          }
          if ($cat_id) {
            $result =  wp_set_post_terms( $post_id, $tags = $cat_id, $taxonomy = 'category', $append = true );
          }
       }
    }
    add_action('publish_post','mam_add_category');
    Thread Starter ismaelhaider

    (@ismaelhaider)

    Thanks for the reply,It means I manually add all keywords with categories, sorry I am little bit new in WP, can tell me in which file I need to add this code and which line ?

    If you like, I can change the code so that it looks in the title for a single word, followed by a blank and the word ‘Scholarship’. If it finds this, and there is a category that matches the first word, add it to the category. That way you would only need to set up the categories.

    However, that first word would need to match exactly, so ‘Phd’ would need a category of ‘Phd’, not ‘PHD’.

    Would you prefer that?

    Thread Starter ismaelhaider

    (@ismaelhaider)

    Its intresting, Here is website where I am grabing data for scholarship

    https://www.scholarships-links.com/

    and this is my testing website

    https://ismailhaider.com/testing

    Give me your skype ID or add me in skype:[moderated – these forums do not provide support via Skype.]
    I will send you the admin pass

    I want to be your fan/friend ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Move Post to specific category Based on Title’ is closed to new replies.