Forums Forums Search & Filter Pro Dropdown 'author' taxonomy showing empty options

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #206739

    Hi again, this is regarding the CoAuthors Plus plugin and the help you provided previously.

    The dropdown is showing empty options (see screenshot here) which when you click on any of the options that only have the count listed, no results show up. Is there anyway to hide these extra empty options?

    Here is the code again:

     if ( ! function_exists( 'visual_posted_on' ) ) :
    /**
     * Integrate Co-Authors Plus with TwentyTen by replacing twentyten_posted_on() with this function
     */
    function visual_posted_on() {
        if ( function_exists( 'coauthors_posts_links' ) ) :
            printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
                'meta-prep meta-prep-author',
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                coauthors_posts_links( null, null, null, null, false )
            );
        else:
            printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
                'meta-prep meta-prep-author',
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
                    get_author_posts_url( get_the_author_meta( 'ID' ) ),
                    esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
                    get_the_author()
                )
            );
        endif;
    }
    endif;
    
    function filter_function_name($input_object, $sfid) {
      if ($input_object['name'] == '_sft_author') {
        global $coauthors_plus;
        foreach($input_object['options'] as $key => $option) {
          if($option->value=="") {
            $option->label = "Search by Author";
          } else {
            $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    		$input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    Anonymous
    #206740
    This reply has been marked as private.
    Trevor
    #206752

    It does that even if you have Hide Empty ON in the field setting? If you enable Count there also, does it show zeros?

    Anonymous
    #206758

    There is no change whether I have Hide Empty ON or OFF, or if I have Enable Count ON or OFF.

    Trevor
    #206760

    It doesn’t show the counts?

    Anonymous
    #206761

    The Display Count does not show zeros. The count that appears immediately after display name shows the correct number of results. The counts that are on their own lines are the ones that do not show results.

    Trevor
    #206764
    This reply has been marked as private.
    Anonymous
    #206792

    Trevor, you are awesome! Thanks for troubleshooting again. Would not have arrived at this on my own.

    FINAL code:

    function filter_function_name($input_object, $sfid) {
      if ($input_object['name'] == '_sft_author') {
        global $coauthors_plus;
        foreach($input_object['options'] as $key => $option) {
          if($option->value=="") {
            $option->label = "Search by Author";
          } else {
            $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option->value );
    	if ($user->display_name=='') {
    	  unset($input_object['options'][$key]);
    	} else {
    	  $input_object['options'][$key]->label = $user->display_name . ' (' . $option->count . ')';  
    	}
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    Trevor
    #206802

    Thanks for sharing that code Deanna. I will close the thread for now.

Viewing 9 posts - 1 through 9 (of 9 total)