Search Results for 'sf_input_object_pre'

Forums › Forums › Search › Search Results for 'sf_input_object_pre'

Viewing 10 results – 81 through 90 (of 146 total)
  • Author
    Search Results

  • Anonymous
    Inactive

    FINAL code:

    Okay, so the code required included that original bit. Here is the final code in the inc/template-tags.php file:

    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);

    Also, added Relevanssi plugin per your guidance and enabled it within SF Pro search form > Advanced settings.

    Really appreciate your continued support on this issue! Glad to have it resolved now.


    Anonymous
    Inactive

    Okay, so that code it still not working for me. I added it just beneath my original code. See below:

    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( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                coauthors_posts_links( null, null, null, null, false )
            );
        else:
            printf( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    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', 'visual' ), 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 = "All Authors";
          } 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);

    Should I remove the first part of that code and only have the part you gave me?

    The “All Authors” dropdown is still not recognizing additional authors, i.e. Wael (only ones in the first position on a post). And the search field is not recognizing them either. Thanks again for your quick responses.


    Trevor
    Participant

    Ok, so it must go in the file you suggested.

    The only bock of code you would have need to add was this, I think:

    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 = "All Authors";
          } 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);

    The question is, is that code working? Does the field show ‘All Authors’ in the choice box?

    If so, if you edit just that one line to change that label, does it then change in the front end?


    Anonymous
    Inactive

    Thanks for your quick response, Trevor. However, I had tried that solution before posting here and it did not work for me. I’m using a child of the Visual Theme. When adding the CoAuthors plugin to the site, this was the code I added into my template-tags.php file in my child theme:

    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( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    get_permalink(),
                    esc_attr( get_the_time() ),
                    get_the_date()
                ),
                coauthors_posts_links( null, null, null, null, false )
            );
        else:
            printf( __( '%2$s &nbsp;<span style="color:#999;">/</span>&nbsp; %3$s', 'visual' ),
                'meta-prep meta-prep-author',
                sprintf( '<span class="entry-date">%3$s</span>',
                    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', 'visual' ), get_the_author() ) ),
                    get_the_author()
                )
            );
        endif;
    }
    endif;

    Then, I added the Trial by Fire code after:

    // Trial by fire
    
    function filter_function_name($input_object, $sfid) {
    
    	if ($input_object['name'] == '_sft_author') {
    
    		global $coauthors_plus;
    		
    		//udpate this field before rendering
    
    			foreach($input_object['options'] as $key => $option) {
    
    				if($option->value=="")
    					{//the option with no value is always the "all items" or unselected state
    						$option->label = "All Authors";
    					}
    
    				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);

    But still no dice. I’m not sure what I’m missing here, but what should be happening is that when I search for Wael in the search box or even in the dropdown Authors box he should be appearing. But he is not. I would appreciate any further help you can provide. I am stumped.

    #205996

    Anonymous
    Inactive

    Hi, I have a requirement for a search to select posts (staff members) from their second name letter.

    So a list of radio inputs – A B C D… Z

    When you click on a letter it would filter the post search and only show people who’s second name begin with that letter.

    I’m sure this is possible but please can you point in the right direction!

    I have been looking at the sf_input_object_pre filter

    This seems like the correct one to use.

    #203304

    Ross
    Keymaster

    Hi there

    I understand the scenario.

    We have a filter, to change the default in the search form, but this won’t affect the results.

    This would be the code (untested ofc):

    function filter_input_object_categories($input_object, $sfid){
    
    	//ensure we are only filtering the correct field name - in this case the field we want to filter has the name <code>_sft_marketplace</code>
    	if($input_object['name']!='_sft_marketplace'){
    		return $input_object;
    	}
    	
    	//manually set the values shown/selected in the field - must be array even if single value
    	//this should really only occur under specific conditions, otherwise your field will be permanently set to this value
    	
    	//if the field is not already in use / selected
    	if(!isset($_GET['_sft_marketplace'])){
    		//then set it to "best wordpress app themes"
    		$input_object['defaults'] = array("best-wordpress-app-themes");
    	}
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object_categories', 10, 2);

    Thanks

    #201644

    Anonymous
    Inactive

    Thanks for the help Trevor! fixed it with the below code, nice one.

    function yothop_sf_filter($input_object, $sfid)
    {
    if($input_object[‘name’]==’_sfm_location’)
    {
    $options = $input_object[‘options’];
    $new_options = [];
    foreach ( $options as $option=>$value ) {
    $is_numeric = is_numeric($value->value);
    if(!$is_numeric){
    $new_options[] = $value;
    }
    }
    $input_object[‘options’] = $new_options;
    }

    return $input_object;
    }
    add_filter(‘sf_input_object_pre’, ‘yothop_sf_filter’, 10, 2);

    #201473

    Anonymous
    Inactive

    Ok, so if I understand well the plugin does allow to render results on page load, but doesn’t allow to filter those results.

    What about the following:
    Is the sf_input_object_pre filter hook not called on page load? If it is, I could check if the ‘from data’ field is empty and if so I’d add the present date to the $input_object.

    Could this work?

    Thank you in advance

    #199420

    Trevor
    Participant

    If you mean how they display in the dropdown select in the form, you would need to do this using our https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object filter.

    I do not know if there are any snippets showing how other users have done anything similar, but you might find the posts that this search returns useful:

    https://support.searchandfilter.com/forums/search/sf_input_object_pre+sort/

    #196334

    Anonymous
    Inactive

    Hello Team,

    No matter where I search, I can’t find a way to make the plugin run on page load.

    Once I start clicking around, the ajax filtering works fine, but I need it to work on the first page load too.

    We are using the code below to remove one of the options and to set the default active item. This all works fine.

    // Remove “All Courses” option and set main to default on Our Menu.
    add_filter( ‘sf_input_object_pre’, function ( $input_object, $sfid ) {
    if ( $sfid == 120 ) {
    // var_dump($input_object);
    if ( ( $input_object[‘name’] = ‘_sft_course’ ) ) {
    if ( empty( $input_object[‘defaults’][0] ) ) {
    $input_object[‘defaults’] = [ ‘main’ ];
    }
    $key = array_search( ‘All Courses’, array_column( $input_object[‘options’], ‘label’ ) );
    if ( $key !== false ) {
    unset( $input_object[‘options’][ $key ] );
    $input_object[‘options’] = array_values( $input_object[‘options’] );
    }
    }
    }

    return $input_object;
    }, 10, 2 );

    Can you please tell me how to instruct the plugin to run in the fresh page load?
    I can’t find the answer anywhere in the docs or internet.

    Thank you very much,
    Kota

Viewing 10 results – 81 through 90 (of 146 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.