Support » Fixing WordPress » Get Categories from ‘Page’

  • I manage to get the ‘category’ and ‘tags’ in Pages by doing so:

    add_action( 'init', 'enable_tag_category' );
    function enable_tag_category() {
        register_taxonomy_for_object_type('post_tag', 'page');
        register_taxonomy_for_object_type('category', 'page');
    }

    Now, I am trying to get the categories assigned in the page and not haveing any luck. I tried:

    
    wp_get_object_terms( $pageID, 'category', array('orderby' => 'term_id', 'hide_empty' => false) );
    get_object_taxonomies( $page->page_type, 'objects' );
    get_terms(array('taxonomy' => 'category','hide_empty' => false));
    

    … but none seem to work. Any suggestions to try out? Thanks.

    [I asked this question in stactexchange as well but didn’t get any response]
    http://wordpress.stackexchange.com/questions/253569/get-categories-from-page

    If there is another way to enable Tag and Category plus the retrieval method, I am happy to test those out.

Viewing 3 replies - 1 through 3 (of 3 total)
  • where exactly, in which template file, are you trying those codes?

    Thread Starter droidxn

    (@droidxn)

    Hi Michael,

    The code below is in functions.php of my theme folder:

    add_action( 'init', 'enable_tag_category' );
    function enable_tag_category() {  
        register_taxonomy_for_object_type('post_tag', 'page');
        register_taxonomy_for_object_type('category', 'page');  
    }

    With the above code, I can see the “Tags” and “Categories” column when I go to Pages. Actually, when I hover over the “Pages” I can see Tags and Categories menu items.

    Now to get the Categories and Tags that I have entered in the Pages, I have done this:
    (The code below is at myTheme/page-templates/my-parent-page.php)

    $pages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'asc' ));
       foreach( $pages as $page ){
          $pageID = $page->ID;
          // there is where I tried the codes to get the Categories
          //$categories = wp_get_object_terms( $pageID, 'category', array('orderby' => 'term_id', 'hide_empty' => false) );
          //$categories = get_object_taxonomies( $pageID, 'category' );
          //$categories = get_terms(array('taxonomy' => 'category','hide_empty' => false));
          //$categories = get_categories(); 
    }
    • This reply was modified 7 years, 1 month ago by droidxn.
    • This reply was modified 7 years, 1 month ago by droidxn.
    Thread Starter droidxn

    (@droidxn)

    I will appreciate if someone could point me to the right direction. Thanks much for your interest.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Categories from ‘Page’’ is closed to new replies.