Forums Forums Search Search Results for 'results'

Viewing 10 results - 1 through 10 (of 12,388 total)
  • Author
    Search Results
  • #288385

    Anonymous
    Inactive

    Hello, I just wanted to tag onto this as I’m having the same issue. The keyword search only seems to work on Posts for me, but not when I set the search to include my custom post types. I also had a post types dropdown where I’d select the CPT, but as soon as I do a keyword search I get no results. And I’m testing specifically with the title.

    #288374

    Anonymous
    Inactive

    Provided by Stefan
    In case someone else runs into this problem, this works to add the form to multiple pages:

    function my_set_sf_resultsURL( $url, $sfid) {
    $url = get_permalink();
    return $url;

    }
    add_filter( ‘sf_results_url’, ‘my_set_sf_resultsURL’, 10, 2 );

    #276869

    Anonymous
    Inactive

    Hey @Trevor!

    Been trying a bit more code but got no results, so not worth sharing this time.

    It’s like the query is not applying, even if we disable ajax…

    Could use some help from your part.

    Thanks in advance.

    #276863

    Anonymous
    Inactive

    Howdy Trevor!

    Instead of a range date picker, we’re gonna go with only one date picker.

    The thing is we need to query from that date in advance, so we did with this code.

    function filter_query_args( $query_args, $sfid ) {
    
    	// Trainings Form ID.
    	if( 1788 === $sfid && ! empty( $_GET['_sfm_start_date'] ) ) {
    		$year  = substr( $_GET['_sfm_start_date'], 4, 4 );
    		$month = substr( $_GET['_sfm_start_date'], 2, 2 );
    		$day   = substr( $_GET['_sfm_start_date'], 0, 2 );
    		$fdate = $year . $month . $day;
    
    		$query_args['posts_per_page'] = -1;
    		$query_args['orderby']      = 'meta_value_num';
    		$query_args['meta_key']     = 'start_date';
    		$query_args['meta_value']   = $fdate;
    		$query_args['meta_compare'] = '>=';
    		$query_args['meta_query']   = [[
    			'key'     => 'start_date',
    			'value'   => $fdate,
    			'compare' => '>',
    		]];
    
    		/*$q = new WP_Query( $query_args );
    
    		print '<pre><br><br>';
    			//print $fdate . '<br>';
    			print count( $q->posts ) . '<br>';
    			//print_r( $query_args );
    			//print_r( new WP_Query( $query_args ) );
    
    			foreach( $q->posts as $p )
    				print get_post_meta( $p->ID, 'start_date', true )
    					. ' : ' . $p->post_title . '<br>';
    		print '</pre>';*/
    	}
    
    	return $query_args;
    
    }
    add_filter( 'sf_edit_query_args', 'filter_query_args', 99, 2 );

    We’ve modified the query correctly, or that says the debug (as you can see commented in the code). The data is there, but somehow the results are not showing.

    Any hints? Thanks in advance.

    #276839

    Anonymous
    Inactive

    Here’s a function for functions.php that will enable searching by title only, in various post types, without installing any other plugins. Hope this helps!

    
    /**
    * Fix search results in admin to search by page title only
    * Modified from: https://developer.wordpress.org/reference/hooks/posts_search/
     *
     * @param String $search
     * @param Object $wp_query Object
     * @return void
     */
    function __search_by_title_only( $search, $wp_query ) {
    	global $wpdb;
    
    	$enabled_post_types = array(
    		'post-type-slug',
    		'another-post-type',
    	);
    	if ( empty( $wp_query->query_vars['post_type'] ) || ! in_array( $wp_query->query_vars['post_type'], $enabled_post_types ) ) {
    		return $search; // skip processing - not an enabled post type
    	}
    
    	$q = $wp_query->query_vars;
    	$n = ! empty( $q['exact'] ) ? '' : '%';
    
    	$search    =
    	$searchand = '';
    	if ( empty( $q['search_terms'] ) ) {
    		$q['search_terms'] = array();
    	}
    	foreach ( (array) $q['search_terms'] as $term ) {
    		$term      = esc_sql( $term );
    		$search   .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
    		$searchand = ' AND ';
    	}
    
    	if ( ! empty( $search ) ) {
    		$search = " AND ({$search}) ";
    		if ( ! is_user_logged_in() ) {
    			$search .= " AND ($wpdb->posts.post_password = '') ";
    		}
    	}
    
    	return $search;
    }
    add_filter( 'posts_search', '__search_by_title_only', 1000, 2 );
    
    
    #276827

    In reply to: Post Tag Search


    Anonymous
    Inactive

    how do i get the results of all posts included. e.g. every post from category1 OR everything from category3 and category4. At the moment unless post has BOTH category1 AND category2 it does not show which I think is incorrect behavier?

    #276816

    In reply to: Promoted posts?


    Anonymous
    Inactive

    Hi! I’m trying to follow these instruction for what I believe is the same goal, but I’m clearly doing something wrong – I’m not getting any search results after I set it up the new way.

    In my case it’s people, not cars; but otherwise the same: I’d like search results to be sorted by first name BUT if someone has “featured” set to “yes”, (an ACF field I’ve set up), I’d like them to come first in the search results regardless.

    I added a Button Group named “featured” with Yes and No options, and No as the default.

    Right now everybody has this set to “No”.

    In the search form settings, under the Posts tab, I tested setting the Default Order to “Meta value” and choose “featured” (no leading underscore). Secondary sort order was set to “first_name”. But whatever I search on with these sorting settings, I never get any results.

    If I only order by first name, then I get the expected list of people.

    Am I misunderstanding something about how to implement this?

    Thanks!

    #276773

    Trevor
    Participant

    An update (on 2023-04-17) from a user (Michael Briel):

    This doesn’t work any more, since

    weglot_get_current_and_original_language()

    doesn’t exist any more in Weglot. Also the solution is for one case only (…/references/…).

    I created a new version of the fix that works even more flexible, since I use it on a page with several different search pages – it doesn’t use a fixed url, but takes the one incoming and uses it, no matter which – meaning: When the search page is http://www.abcd.com/testsearchpage/ it takes the “/testsearchpage/-part and uses it:

    function modify_sf_results_url( $url, $sfid ) {
    $current_language = weglot_get_current_language();
    $relative_url = str_replace( home_url(), "", $url );
    
    if ($current_language === "en") {
    // nothing, since en is main language - replace "en" with your main language if needed
    } else {
    $url = home_url("/".$current_language.$relative_url."");
    }
    return $url;
    }
    add_filter( 'sf_results_url', 'modify_sf_results_url', 10, 2 );
    #276745

    Anonymous
    Inactive

    In case someone else runs into this problem, this works to add the form to multiple pages:

    function my_set_sf_resultsURL( $url, $sfid) {
    $url = get_permalink();
    return $url;

    }
    add_filter( ‘sf_results_url’, ‘my_set_sf_resultsURL’, 10, 2 );

    #276737

    In reply to: Result load speed


    Trevor
    Participant

    I replied to your ticket in our support area, but I will copy that reply here also.

    The other content you mention is static, and so can be held in cache. However, search results have to be made using read/writes with your server hard drives, and this is where the bottleneck will be. Cached content will not have to do this, and so will be much faster.

    There is no way to avoid this where you have dynamic (uncached) content.

Viewing 10 results - 1 through 10 (of 12,388 total)