‘and’ ‘or’ but no ‘not’ [exclude]
-
Hi,
I have recently combined [via import] three websites into one. The media library has over 2.5K images most of which have been given Att.Categories and Att.Tags. Is there a way to restrict search by what used to be called the ‘not’ term.For example:
I have a parent category of ‘Property’ and a subcategory of ‘Features’. If I search for ‘features’ it gives me the expected result of images which have the category or tag ‘features’ attributed to them. But if I search for property, I can’t see a way of excluding images with the property category or tag which don’t have ‘features’ also.In the search field there is the option of ‘And’, ‘Or’, but no ‘Not’.
In plain English I want to search for any image that has the word ‘property’ but not ‘features’ associated with it in some way.
Any help or suggestions please?
Thanks
-
Good to hear from you again – it’s been a while. Thanks for your question and the detailed example of what you’d like to do. I want to make sure I understand your goal.
MLA provides separate features for searching by “keywords” or by term names. It looks like you are interested in searching for a combination of Att. Categories term names; is that right?
MLA provides search features on the Media/Assistant admin screen (the “Search Media” text box) and for the
[mla_gallery]shortcode. It looks like you want an admin-mode search on the Media/Assistant admin screen; is that right?For the
[mla_gallery]shortcode you can use the WordPress “tax_query” support to get what you want. See the ‘Taxonomy Queries, the “tax_query” ‘ section of the Settings/Media Library Assistant Documentation tab for more details. If, however, you want to enter something in the Search Media text box the solution will be more difficult.The existing “And”/”Or” radio buttons are outside the text box and apply to all keyword/term name values in the text box. For your application you will need some way of specifying which terms are included and which are excluded. I did something like this for an earlier topic:
For your example you would code something like
property /featuresand use the “And” connector. If all of this makes sense and I have understood you correctly I can look into the feasibility of adding something to the Media/Assistant Search Media box. Let me know what you think.Hi David,
thank you for the very prompt response.
I had a feeling that what I was asking for was probably tricky, otherwise, it’s likely to have been part of the interface already πI’ve might have over confused things in the way that I have referred to Att.Categories and Att.Tags.
To simplify the request it would be to have an additional radio button alongside the And/Or buttons on the admin screen for ‘Not’ [or ‘Exclude’ if you prefer]. This would apply to keywords in the ‘Search Media’ text box and would allow us to select an Att.Category or Att.Tag and ‘exclude’ a particular keyword from the search.
So in my scenario, ‘Features’ are a child category of the ‘Property’ category. But currently, unless I’m missing an alternative way of approaching this [hence my question in the forum], I can’t see a way of searching in the admin screen media library for only images with the category of ‘Property’ but not ‘Features’. The reverse is easy of course because searching for features only can be narrowed down.
I’m not overly technical, so it may be that there is an easier solution. I’m old school and remember search functions having the option of ‘Not’, so it’s possible I’m just stuck with the old mindset π
Hope this makes things slightly clearer or confirms what you thought.
Cheers.
Thanks for the additional information. I will have a look at the code and see if there’s a feasible way to extend the “Search Media” functions. I will also look at the “Terms Search” function and the
[mla_gallery]parameters so that all of the ways to search for term names have similar results.I will post an update here when I have progress to report.
Wow – thank you David.
Not really expecting that, I thought there may be a way with the current interface that I was missing!Cheers
SteveThanks for your patience in awaiting my progress report. Adding an “exclude” feature to the Search Media and Terms Search functions turned out to be more, well, interesting than I expected.
First, simply adding a “not” or “not in” alternative to the existing logic does not work because items can have multiple term assignments and each assignment is independent, with a separate database entry. Using the example of “property” and “not features”, the item you want to exclude has two separate term assigmments, “property” and “features”. The simple SQL is something like
SELECT TERM IN ('PROPERTY') AND TERM NOT IN ('FEATURES'). The items assigned to both terms still show up because thePROPERTYterm assignment passes both tests.The “right” answer is more along the lines of 1) select all the items assigned to
PROPERTY, and then 2) remove all the items assigned toFEATURES. Two queries are required to get the answer that makes sense.Second, there are three methods to filter the items displayed and a good solution must work for all combinations of the methods. The Media/Assistant screen has 1) a dropdown control for filtering items by one specific term, 2) the “Search Media” text box and 3) the “Terms Search” popup window. As you observed, you can set the dropdown control and then add the Search Media text to further refine the results. You can also enter a Search Media value for, say, the Title and Description values and then use “Terms Search” to further refine the results.
Finally, the Search Media and Terms Search methods allow for multiple phrases and terms, connected by AND or OR, and phrases can have multiple words. For example, you could search for
"PERSONAL PROPERTY"OR"REAL PROPERTY"and excludeTANGIBLE, which would also exclude items assigned to"COMMUNITY PROPERTY". Note the quotes around the multi-word phrases.The solution is to provide “exclude” delimiters (“/”) you can use to enclose any part of the Search Media or Terms Search values. The values are divided into two sub-values, “positive” and “negative”, with everything enclosed by the exclude delmiters going to the negative sub-value and everything else to the positive. Two queries are performed. First, the negative sub-value is used and a list of the item ID values that pass the query is compiled. Second, the positive sub-value is used and items with the “negative” ID values are excluded.
The example can be entered in the Search Media box as
property /features/, or you can select “property” in the dropdown control and enter/features/in the Search Media box, or you can enterpropertyin the Search Media Box, click “Terms Search” and enter/features/in the popup window. Of course, the “Terms” box below the Search Media box must be checked as well.I have uploaded a new MLA Development Version dated 20190122 that contains the new feature. You can find step-by-step instructions for using the Development Version in this earlier topic:
PHP Warning on media upload with Polylang
If you get a chance to try the Development Version please let me know how it works for you. Thanks for motivating this useful MLA enhancement. I will work on adding the feature to the
[mla_gallery]shortcode as time permits.WOW!, Thanks David,
are there any downsides to installing the development version on a live site?Steve
Well, there’s always a small chance of a problem, but I don’t upload anything if I think there’s a risk. You can always delete the plugin and reinstall the production version if you need to; you won’t lose any settings or other data.
The changes in the current Development Version from the current production version are minor and won’t affect front-end access. Let me know if you have other questions or concerns.
Cheers,
I’ll give it a go π
SteveJust tried it on non live site, works a treat π
SteveThanks for digging in and for the good news. I’d appreciate as much testing and different combinations of search values you can think of. Let me know if you find any problems.
Thanks David,
Iβll give it some serious testing when I have a bit more spare time.For now though, looking good. Thank you once again for taking the time to work on this.
Very much appreciated.
SteveI have released MLA version 2.78, which contains the new “exclude” feature.
I am marking this topic resolved, but please update it if you have any problems or further questions regarding the new version. Thanks again for your help with this new feature.
Perfect – thanks again David π
You’re a star
Steve
The topic ‘‘and’ ‘or’ but no ‘not’ [exclude]’ is closed to new replies.