Hiding parent category from add classified form

Discussion in 'GeoCraft WordPress Theme' started by anuj, Jun 18, 2013.

Thread Status:
Not open for further replies.
  1. anuj

    anuj New Member

    Joined:
    May 28, 2013
    Messages:
    14
    Likes Received:
    0
    Location:
    New Delhi
    Hello
    Please let me know how to show only the child category on the front end form while adding a classified.I don't want to show the the categories which have child category on the form select menu.


    thanks in advance
     
  2. anuj

    anuj New Member

    Joined:
    May 28, 2013
    Messages:
    14
    Likes Received:
    0
    Location:
    New Delhi
    Never mind, I have resolved the problem, once I got the file where the code for the select box is written , I have changed it and its working fine now.
    if anyone wants to achieve the same, below is the code.
    File path: Open /library/control/theme_functions.php
    Search
    Code:
    function cc_get_terms_dropdown($taxonomies, $args) {
        $myterms = get_terms($taxonomies, $args);
        $output = "<select name='cc_category'>";
        foreach ($myterms as $term) {
            $root_url = get_bloginfo('url');
            $term_taxonomy = $term->taxonomy;
            $term_slug = $term->slug;
            $term_name = $term->name;
            $link = $root_url . '/' . $term_taxonomy . '/' . $term_slug;
            $output .="<option value='" . $term_slug . "'>" . $term_name . "</option>";
        }
        $output .="</select>";
        return $output;
    }
    
    and replace the code with the below code
    Code:
    function cc_get_terms_dropdown($taxonomies, $args) {
        //This gets top layer terms only. 
        $parent_terms = get_terms($taxonomies, array('parent' => 0, 'orderby' => 'id', 'hide_empty' => false)); 
        $output = "<select name='cc_category'>";
        foreach ($parent_terms as $pterm) {
        $myterms = get_terms($taxonomies, array('parent' => $pterm->term_id, 'orderby' => 'id', 'hide_empty' => false));
        foreach ($myterms as $term) {
            $root_url = get_bloginfo('url');
            $term_taxonomy = $term->taxonomy;
            $term_slug = $term->slug;
            $term_name = $term->name;
            $link = $root_url . '/' . $term_taxonomy . '/' . $term_slug;
            $output .="<option value='" . $term_slug . "'>" . $term_name . "</option>";
        }
        }
        $output .="</select>";
        return $output;
    }
    Result: it will display only the child category on the select box in add ad form.
    Note: I have changed the value of orderby to id so that one can easily order the category by creating then in sequence in which they want to order in the form

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page