Jump to content
prestoav

Issue with '-' in selector text?

Recommended Posts

Hi all,

I'm having an odd issue that I think is down to the selector I'm using but I can't track down the cause!

I'm using front-end AJAX search form on a list of product adverts (pages)  where the product is made by a certain manufacturer (vendor). The manufacturer is chosen buy the person listing the adverts from a page field list of manufacturers who's parent is id=1034.

Most manufacturers are being found without an issue. The only one that's causing a problem is called 'Proj-ect" (the "-" being part of their brand name.

Here's my selector code:

$thisBrandProducts = $pages->find("template=advert,vendor.title~=$q,has_parent=1034,limit=20,created_users_id!=$susDealerList");

$susDealerList is a list of advertisers that are not currently live so pages should be excluded.

Could the "-" in the name be the issue with those pages not being returned? If so does anyone have any ideas of how I can get around this?

Thanks in advance!

Share this post


Link to post
Share on other sites

Did you try wrapping the keyword with `backticks` ? Or use %= instead of ~= ?

Share this post


Link to post
Share on other sites
5 hours ago, dragan said:

Did you try wrapping the keyword with `backticks` ? Or use %= instead of ~= ?

Thanks dragan, the "%" cures this issue but introduces another. Using "%" stops searches working where there are more than word in the search term and they are not connected.

Example:

There is a manufacturer called 'Bowers & Wilkins'. Some people search for 'Bowers and Wilkins'. To make this manufacturer show up no matter if the user uses the "and" or or the "&" I do a str_replace on trhe search term to remove both the "&" and "and" so there are just the two words 'Bowers' and 'Wilkins. Then the search works as the two words are present even thought they are not one after the other.

(I hope that makes sense)!

Can you tell me more about your 'backticks' suggestion as I'm not sure what you mean?

Thanks. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By iipa
      Hi!
      I have two Page Reference fields: Category and Subcategory. Category is parent of Subcategory, and can have 0 to n Subcategories. Fields are selected by dropdown selection.
      I'm trying to achieve following logic:
      1. Select Category (obviously works)
      2. Change Subcategory options based on selected Category (this works)
      3. Hide the Subcategory field if Category has no Subcategories (to prevent weird dropdown with nothing to select)
      I have tried to investigate two possible alternatives to achieve step 3:
      A) Make dynamic condition into Subcategory selection's "Only visible if..." field
      B) Make a hook that fires when Category changes, then hides Subcategory field if Category has no children
      So far I haven't been successful in either. Conditions I've tried always lead to hidden field, and I haven't been able to find set up a hook that fires on field change.
      So here's the question (finally): Is there a way to alter field visibility in API, for example in ready.php or inside a hook? In API I could loop through categories, find the ones that have children and then make a selector based on their IDs.
    • By schwarzdesign
      I'm working on a news feed that will show the most recent news in a full teaser grid, and all older news as a simpler archive-type list view. My selectors so far:
      $news_full = $page->children("template=news, limit={$page->feed_count_full}"); $news_archive = $page->children("template=news, start={$page->feed_count_full}, limit=9999"); The $page->feed_count_full field controls how many items to show in the teaser grid (I've confirmed it contains the correct value, and the $news_full selector works as intended).
      This works, but I don't like the limit in the second selector. Unfortunately, if I leave it out (i.e. I only specify a start, not a limit), the start is ignored and I get all news instead. Not a big problem as we will never have more than 9999 news, but it still bothers me, as semantically speaking I don't want to set a limit in this case.
      Is this the intended behaviour of start/limit selectors? Is there a cleaner way to specify an offset (start selector) without a limit?
      ProcessWire Version 3.0.123
      Thanks!
    • By pwFoo
      I played with the Selectors object and would like to use it for a special use case...
      That is a custom Selectors object with dummy data converted to an php array to see the structure (Selectors object is a WireArray with "fields" added)
      Array ( [0] => Array ( [0] => Array ( [field] => seg1 [value] => val1 [not] => [group] => [quote] => [forceMatch] => ) [1] => Array ( [field] => seg2 [value] => val2 [not] => [group] => [quote] => [forceMatch] => ) ) )  
      But instead of "seg1" the field name is "field" with value "seg1" (= my field name).
       
      So I can't search the Selectors WireArray (= custom WireArray with added Selectors objects) with PW "find('seg1=val1')", Is there a way to search with "find()" or build a simple wrapper to make the elements searchable / filterable with find()?
    • By Peter Knight
      <?php $Cats=$pages->find("parent=1086, id!=$page, sort=sort"); foreach($Cats as $Cat) { echo " I have a selector that pulls in 4 child pages of a parent and the order is set to reflect the order of the tree.
      My client has asked that instead of
      Cat 1 | Cat 2 | Cat 3 | Cat 4
      we instead display
      Cat 4 | Cat 1 | Cat 2 | Cat 3 
      However, I can't change the sort order in the tree.
      Can anyone guide me on the correct approach here?
      Thanks
       
    • By theoretic
      Hi there! And thanks for Processwire!
      It appears that i've found something interesting about PW selectors. They should only be strings! Here's an example of SQL-like syntax for selector:
      $my_complex_selector = " name='some name', parameter=123, other_parameter=[subparam>=subvalue] "; Trying to use this selector lead to a very buggy PW behaviour. It appears that newlines are treated in a very special manner by PW selector engine, preventing the newlined selectors from working as expected.
      I cannot imagine a situation when an unescaped newline could be a part of selector or selector value, so stripping newline symbols from selector could be a good idea for further PW development. And, currently, another good idea is to write complex selectors as PHP arrays:
      $my_complex_selector = [ "name=$name", "param1=$param1", ]; and to implode them into a single line before using find() and other functions which use selectors.
      Sorry if i wrote something trivial, but having this post already present at support forum could save me a couple of hours. Hope mine will save that tame for someone else 😉
×
×
  • Create New...