• Carin

    (@sparksfreebies)


    I found the snippet for “”

    works great! but when I click on a Subcategory it now says “no category found” on the subcategory page (the sub categories in my case do not have additional sub categories) I could not find a simple way to modify the snippet to apply to only Top Level categories, can you help?

    add_action( "adverts_sh_list_before", "categories_above_adverts_list" );
    function categories_above_adverts_list( $args ) {
      global $wp_query;
      if( is_tax( 'advert_category' ) ) {
        $current_category = $wp_query->get_queried_object_id();
        // code for getting the sub categories and displaying them here
        $columns = "adverts-flexbox-columns-4";
        $show_count = 0;
        $terms = get_terms( 'advert_category', array( 
            'hide_empty' => 0, 
            'parent' => $current_category ,
            'number' => 0
        ) );
        include ADVERTS_PATH . '/templates/categories-top.php';
      }
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Carin

    (@sparksfreebies)

    I forgot to add the second part, on editing, I have disabled Posting to Top Level Categories and made Search Forms and Listing Forms applied to my subcategories, but when I created a Category Search dropdown in my Custom Search Form, the Top Level categories are not “greyed out” they can still be searched and yield no results. In the Top Level Category edit pages I have not selected any Form for Search or Listing, https://www.screencast.com/t/nFoIWEyDJlC

    Plugin Author Greg Winiarski

    (@gwin)

    1. change 'parent' => $current_category , to 'parent' => 0 , then it should show always the top categories only.

    2. are you allowing users to select multiple categories? If so then right now the restricting categories work with the single-select only.

    Thread Starter Carin

    (@sparksfreebies)

    Hi Greg,
    For 1: I changed ‘parent’ => 0 , and now it only shows top categories on every page. I am trying to show the subcategories on the Top Category Page, and remove the “no categories found on the Subcategory pages.
    for 2: I changed the Max Choices to 1 on the Search Form, but I can still select the Top Category and it yields no result, https://www.screencast.com/t/tHh45ooFvxk
    (I only have 1 ad in Cars, but when I select Autos in Advanced Search Category dropdown, it shows no ad, https://volusiacounty4sale.com/classified-ads/

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    1. you would need to customize it with a code that will search for the correct category then, i remember there used to be a thread regarding similar feature on this forum about a month or two ago.

    2. i am out of the office today so i cannot check but most likely the filter restricting categories is run only on the default advert_category field.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi again,
    1. in your case the whole code snippet should probably be

    
    add_action( "adverts_sh_list_before", function( $args ) {
      global $wp_query;
      $parent_id = 0;
      if( is_tax( 'advert_category' ) ) {
        $current_category = $wp_query->get_queried_object();
        $term_path = array_keys( advert_term_path( $current_category, "advert_category" ) );
        $parent_id = $term_path[0];
      }
      $columns = "adverts-flexbox-columns-4";
      $show_count = 0;
      $terms = get_terms( 'advert_category', array( 
          'hide_empty' => 0, 
          'parent' => $parent_id ,
          'number' => 0
      ) );
      include ADVERTS_PATH . '/templates/categories-top.php';
    } );
    

    2. regarding the restricted categories i double checked and indeed the restrictions are being applied to the field named advert_category only.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Subcategories editing’ is closed to new replies.