Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dana Ross

    (@csixty4)

    If you grab a copy of version 3.0a2, there’s a “dwls_post_title” filter you can use in your theme’s functions.php file or a custom plugin to change the title.

    You can get the latest “alpha” (although it’s pretty stable & running on production sites) from https://www.ads-software.com/extend/plugins/daves-wordpress-live-search/download/

    – Dave

    Hi espider, first you need to read the value in wordpress into a variable for jQuery:

    Note: My meta-field key is “_museum_city” in the below case.

    $meta_city = get_post_meta( get_the_ID(), '_museum_city', true );
    $result->post_city = $meta_city;

    Then, in your JS file:

    if(searchResult.post_city != undefined) { renderedResult += '<p class="price">' + searchResult.post_city + '</p>'; }

    Hope this helps!

    Thread Starter MTD

    (@espider)

    Hi Bruce, thanks hips for your help.

    I managed to display prices in the search results but it shows the same price for all results unless I go to the next post and then the price changes for the current post ?? What I did is:

    1) added a new function to DaveWordPressLiveSearchResults.php

    function my_jquery_var() {
        global $post;
        if ( $my_custom_field_name = get_post_meta( $post->ID, 'price', true ) ) {
            echo '<script type="text/javascript">var my_custom_field_name = "' . $my_custom_field_name . '";</script>' . "\n";
        }
    }
    add_action( 'wp_head', 'my_jquery_var' );

    2) added new renderResult in dave-wordpress-live-search.js

    renderedResult += '<a href="' + searchResult.permalink + '">' + '<span class="price_search">' + my_custom_field_name + '</span>' + searchResult.post_title + '</a>';

    Once again, thanks big time for your help

    Nice espider! This is the exact same problem that I am running into (the value is repeating for every result)! Can you please paste your entire code, or send me the source so that I can figure this out? I am trying to put your solution in, but am having trouble.

    Here is my code (DavesWordpressLiveSearchResults.php):

    //foreach($posts as $result)
    		{
    			// Get the ID of a given category
    
    			$category_list = get_the_term_list( get_the_ID(), 'portfolio_category', "", " - " );
    			$category_link = get_category_link( $category_id );
    			$result->post_category = $category_edit;
    
        // Get the URL of this category
    			function my_jquery_var() {
        global $post;
        if ( $meta_city = get_post_meta( $post->ID, '_museum_city', true ) ) {
            echo '<script type="text/javascript">var meta_city = "' . $meta_city . '";</script>' . "\n";
        }
    }
    	add_action( 'wp_head', 'my_jquery_var' );
    
    			// Add author names & permalinks

    and the JS code:

    renderedResult += '<p>' + meta_city + '</p>';

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Dave's WordPress Live Search] Custom field in front of title’ is closed to new replies.