• Hi

    I’m having a similar problem with custom fields.

    Every page is made up of modules form custom fields.

    In the Ajax Lite, I have for example, _basicmodules under the ‘Available public custom fields types’. So I’ve tried move all to ‘Drag here the custom fields you want to use!’. But still the content is not coming up in searches, only words form the page title.

    https://www.mblox.com/help/frequently-asked-questions/why-do-messages-fail/

    I’m working on a test sever so the search is not on live.

    What I’m trying to get to is searching only the FAQ pages (I’ve added categories to these pages and made all the pages thus far categorised as FAQ).

    Your help will be much appreciated as it will be exactly what I need.

    Thanks

    https://www.ads-software.com/plugins/ajax-search-lite/

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi!

    I’m not sure if I understand correctly, I will have to ask you a few questions.

    Is the problem: If you search any word from the content, the plugin does not find it, even the custom field is selected?

    Or: The plugin finds the results but the content is not displayed only the title?

    Can you also share the debug information you can find on the Help&Support submenu via https://paste.ee – it would help me a lot!

    Thread Starter sdb7

    (@sdb7)

    Yes. If you search any word from the content, the plugin does not find it. I’ve selected all Available public custom fields types and placed them into the Drag here the custom fields you want to use section.

    With Relevanssi there is an option to select all custom types and that came up with results, which shows the fields are searchable.

    Does this link work for you?

    https://paste.ee/p/ox0KI

    Thanks

    Plugin Author wpdreams

    (@wpdreams)

    The query looks okay to me for the first sight, so I can only guess.

    Is the module content indeed stored within the custom fields as text? The custom field content might be only a reference to something (to a shortcode, or another object).

    My other guess is that the custom fields in question might not be listed there. Since you want to search all custom fields, I can suggest a modification to the code to ignore custom field keys and just check the values. For that you will have to open up the wp-content\plugins\ajax-search-lite\includes\classes\search\search_content.class.php file and find lines 190-207:

    if ( isset( $searchData['selected-customfields'] ) ) {
    	$selected_customfields = $searchData['selected-customfields'];
    	if ( is_array( $selected_customfields ) && count( $selected_customfields ) > 0 ) {
    		$words = $options['set_exactonly'] == 1 ? array( $s ) : $_s;
                  $op = 'OR';
    
    		foreach ( $selected_customfields as $cfield ) {
                      if ( count( $_s ) > 0 ) {
                          $_like = implode( "%'$suf_like " . $op . " " . $pre_field . $wpdb->postmeta . ".meta_value" . $suf_field . " LIKE $pre_like'%", $words );
                      } else {
                          $_like = $s;
                      }
                      $parts[] = "( $wpdb->postmeta.meta_key='$cfield' AND " . $pre_field . $wpdb->postmeta . ".meta_value" . $suf_field . " LIKE $pre_like'%" . $_like . "%'$suf_like )";
    		}
    		$postmeta_join = "LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID";
    
    	}
    }

    and replace that with simply:

    $words = $options['set_exactonly'] == 1 ? array( $s ) : $_s;
    $op = 'OR';
    if ( count( $_s ) > 0 ) {
    	$_like = implode( "%'$suf_like " . $op . " " . $pre_field . $wpdb->postmeta . ".meta_value" . $suf_field . " LIKE $pre_like'%", $words );
    } else {
    	$_like = $s;
    }
    $parts[] = "(  " . $pre_field . $wpdb->postmeta . ".meta_value" . $suf_field . " LIKE $pre_like'%" . $_like . "%'$suf_like )";
    $postmeta_join = "LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID";

    This will remove the restriction of checking the custom field keys, and will check values only, regardless if the custom field is selected or not.

    If the content is indeed stored in the custom fields, this should start returning results hopefully.

    Thread Starter sdb7

    (@sdb7)

    Hello

    That worked!

    However, what I’m trying to achieve is an FAQ section with a url tree structure e.g. /faq/landing-page/post-name
    /faq/landing-page2/post-name

    Therefore, I am using Pages for this. The only problem I have now is that although I’ve added categories to FAQ pages, I’d have to go through every page and select Uncategorized as currently it doesn’t seem to want to exclude these “uncategorized” page..unless you can advise otherwise? Perhaps ‘uncategorized’ fields have an ID number I can exclude by? I have excluded the two uncategorized categories that are listed and added category 1 in the Exclude Posts by ID’s (comma separated post ID-s).

    I also found under screen options in the custom fields the ‘Field Keys’ you referred to and therefore I can see the field I want search has a field key of field_570242e6e91d2. This does not show up in the list of Available Public Custom Fields Types, so would be good to know what they do not? As if we can could add them in we could use your code without amendments.

    Really appreciate your quick response and help you’ve given so far.

    Thread Starter sdb7

    (@sdb7)

    Another way to look at this would be whether it possible to run a search on a section of the website. Stipulate searching only child pages of a parent page?

    Is this possible?

    Thread Starter sdb7

    (@sdb7)

    Just done a test on a clean WP install and found that it does exclude uncategorized pages (pages that haven’t been assigned any category), which I thought it had done in previous tests of mine.

    Therefore I can only assume that maybe the replacement code to search all custom fields also overrirdes the exclusion of uncategorized posts in the Exclude categories part of Ajax Lite.

    Is there a way to fix this or better still get my custom fields selectable (as to previous post ‘Field Keys’?

    Thanks

    Plugin Author wpdreams

    (@wpdreams)

    Interesting, I think I might need to test these as well to see if I can find anything useful.

    Which plugin (or other method) do you use to add categories to pages? It might be important.

    Thread Starter sdb7

    (@sdb7)

    Hi

    Plugins are:

    Add Categories To Page

    And

    Advanced Custom Fields Pro

    Thanks

    Thread Starter sdb7

    (@sdb7)

    Just checked with the local clean install and find using the Add Categories To Page works fine with Ajax Lite and does as it should. Which therefore indicates the custom code we added overrides the category search.

    I’d still be keen, if possible, to understand/get working, selecting the custom fields to search.

    Thanks again.

    Plugin Author wpdreams

    (@wpdreams)

    Hi!

    In the meantime I have released an update where I’ve added an option to “search all custom fields”, so the custom code is no longer needed. I suggest updating and using that instead.

    I’ve conducted a few tests on this new version.

    Made 3 pages:

    • Page 1 (category1, uncategorized)
    • Page 2 (category1, category2, uncategorized)
    • Page 3 (uncategorized)

    On the Advanced Option panel I have excluded category1 first.
    Results:

    • Page 3 (uncategorized)

    Then excluded category2. Results:

    • Page 1 (category1, uncategorized)
    • Page 3 (uncategorized)

    Unfortunately this looks correct to me. I’ve also looked at the query to see if there is anything fishy going on, but it’s correct as well.

    Can you please update to the latest version and turn on the “search all custom fields” option to see if that changes anything?

    Thread Starter sdb7

    (@sdb7)

    Hi

    I’ve installed the latest version and checked the update overwrote the previous coding we added and can confirm it has.

    However, the same thing is happening. Any page not assigned a category is coming up in the search results. But if I assigned all pages as ‘uncategorized’ then they don’t come up in search results. However, like it works on Ajax on other typical WP installations (no custom fields), I would like it to recognise pages unassigned as being uncategorized.

    I’ve even tried this on the staging server rather than test just encase there was something else going wrong, but it does the same.

    Every page is created with no standard page content area but instead selectable layout modules e.g. Banner, Page Introduction/full content (where the content to be searched is stored) and seven other selectable modules.

    I can send some screen grabs of the set up or possible give access if that helps get to the bottom of this?

    Thanks ??

    Plugin Author wpdreams

    (@wpdreams)

    Hi!

    Sorry for the late response. I didn’t notice the main difference here: my pages were all in the uncategorized category. It indeed excludes them incorrectly if they are not attached to any of the categories.

    There was a known bug of a similar behavior regarding posts, but I thought I have fixed it some time ago. Let me investigate this further, it’s definitely something that affects other post types as well.

    If possible I will post a solution here, if not then I release a minor update once I got this covered.

    Best regards,
    Ernest Marcinko

    Thread Starter sdb7

    (@sdb7)

    Hi Ernest

    Not a problem. Appreciate your assistance.

    Enjoy your vacation.

    Kind regards

    Steve

    Plugin Author wpdreams

    (@wpdreams)

    Hi Steve,

    I’m back, with possibly good news. So I did a bit of experimenting, and it appears that I have forgotten to update this part of the plugin when I did a similar repair to the PRO version. There is this bug, when an object is not associated with any category, it’s automatically excluded when category exclusions are set.
    It didn’t occur, because posts are automatically added to the “uncategorized” category, even if it’s not selected.

    Anyways, I’m not ready with a final release, but here is a temporary solution:
    Simply replace the ajax-search-lite\includes\classes\search\search_content.class.php file with this one: https://gist.github.com/anag0/e2c6963fd54b0c719508f67846d7bbf7

    After the change, the exclusions should not affect objects without associated categories.

    Thread Starter sdb7

    (@sdb7)

    Welcome back. Hope you had a good break.

    Thanks for doing this. I’ll give it a try when I can and confirm all is ok.

    Kind regards

    Steve

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Custom field content not coming up in search’ is closed to new replies.