Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-04-18 08:46:06

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Can I narrow searches to only articles with certain tags?

Hi all, might be a stupid question but can I limit Textpattern site searches to only show results for articles with certain tags?

For example on the new Textpattern plugins site that I’m starting to work on, I want to limit search results to plugins that are verified to work with a certain Textpattern release. The actual articles are tagged with ‘4.7’, ‘4.6’, etc. so depending on what version the user selects in a select field in the search form, I only want to return article results for that tag.

I have the following code so far (I know the select field isn’t Textpattern tag-ified as yet but this is just for example purposes…

<form class="search-hero" role="search" method="get" action="<txp:site_url />" itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction">
    <meta itemprop="target" content="<txp:site_url />?q={q}">
    <input id="q" name="q" type="search" size="28" placeholder="Search plugins…" itemprop="query-input">
    <input class="button-primary" type="submit" value="Search">
    <br>
    <label for="textpattern-target">Textpattern version compatibility</label>
    <select id="textpattern-target" name="textpattern-target">
        <option selected>4.7</option>
        <option>4.6</option>
        <option>4.5</option>
        <option>4.4</option>
    </select>
</form>

Offline

#2 2019-04-18 10:02:36

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Can I narrow searches to only articles with certain tags?

Hi Phil, you should be able to filter by custom fields (say, target):

<txp:article target='<txp:page_url type="textpattern-target" wraptag="%" />' />

Offline

#3 2019-04-18 10:09:07

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Can I narrow searches to only articles with certain tags?

Hi Oleg,

Thanks. I was thinking more along the lines of a search query string, like is this possible?

https://example.com/?q=gallery&c=4-7

Offline

#4 2019-04-18 10:19:39

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Can I narrow searches to only articles with certain tags?

If you end up using smd_tags instead of categories, you can use etc_search along with a special search query in article context (you put that in Extensions > Search Settings)

Oleg helped me once before to craft a search query like this:

ID IN(SELECT ID FROM textpattern WHERE {Title, Body} UNION ALL SELECT txp.ID FROM textpattern txp JOIN (smd_tags, smd_tags_used) ON (txp.ID=smd_tags_used.item_id AND smd_tags.id=smd_tags_used.tag_id) WHERE {smd_tags.name,smd_tags.title})

And it enables you in combination with the txp:etc_search_results tag to find articles that match the keyword.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2019-04-18 11:21:59

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Can I narrow searches to only articles with certain tags?

philwareham wrote #317673:

I was thinking more along the lines of a search query string, like is this possible?

https://example.com/?q=gallery&c=4-7...

Certainly, but c is reserved for categories, and I don’t think txp version numbers fit well as categories. You could use a custom field (name it target, for example) with values like 4.5 or 4.5+, etc. Then create a HTML form for search input

<form class="search-hero" role="search" method="get" action="<txp:site_url />" itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction">
    <meta itemprop="target" content="<txp:site_url />?q={q}">
    <input id="q" name="q" type="search" size="28" placeholder="Search plugins…" itemprop="query-input" value='<txp:search_term />'>
    <input class="button-primary" type="submit" value="Search">
    <br>
    <label for="textpattern-target">Textpattern version compatibility</label>
    <select id="textpattern-target" name="target">
        <option selected>4.7</option>
        <option>4.6</option>
        <option>4.5</option>
        <option>4.4</option>
    </select>
</form>

and filter search results by target cf:

<txp:if_search>
    <txp:article target='<txp:page_url type="target" wraptag="%" />' />
</txp:if_search>

The form will generate a query string like ?q=gallery&target=4.5 as required.

Core tags should suffice, but if you need more complex search filtering, etc_search can help.

Offline

#6 2019-04-18 11:31:04

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Can I narrow searches to only articles with certain tags?

Thanks Oleg, I did initially have rss_unlimited_categories installed, but I’ve since been trying smd_tags – both to get round the article 2 category limit we currently have.

Obviously I’d rather use core stuff – so custom fields was actually my next thing to test out. Maybe that would be the best solution as I can migrate it to use the planned custom field changes one day (as a select field if that’ll be possible). In the meantime I’d just have to be vigilant that custom field data is keyed in correctly per article in text (input) fields.

I’ll also check out etc_search as I’ve not used that plugin before.

Offline

#7 2019-04-18 11:36:41

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Can I narrow searches to only articles with certain tags?

Is glz_cf not working in 4.7, to facilitate target numbers input?

Offline

#8 2019-04-18 11:46:56

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Can I narrow searches to only articles with certain tags?

etc wrote #317678:

Is glz_cf not working in 4.7, to facilitate target numbers input?

Probably, but I’m trying to keep everything as light as possible. All I really need is a simple way of tagging a plugin as being compatible with certain Textpattern releases. Even smg_tag is way too overkill for what I need to do really.

So I need the current workflow:

2 categories…

1 for whether the plugin is a ‘featured’ plugin or not (we can promote a plugin on the homepage)
1 for what type of plugin it is, i.e. a gallery plugin, comments plugin, etc.

Tags for (at least)…
4.7 compatibility
4.6 compatibility
4.5 compatibility
4.4 compatibility
…etc…

Possibly (undecided yet) also tags for…
Actively maintained
Orphaned (seeking new owner)
Obsolete
…whatever…

Offline

#9 2019-04-18 12:10:32

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Can I narrow searches to only articles with certain tags?

Hmm, yes, txp is not (yet) capable to do <|> comparisons when filtering, so searching for 4.6 compatibility will not match 4.5+. We could actually introduce it in the upcoming release, just need a syntax for, say, <=4.6:

target="4.6-"
target="<=%4.6"
target="something else"

I exclude target<="4.6" atm, this would make parsing tricky.

Offline

#10 2019-04-18 12:13:05

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Can I narrow searches to only articles with certain tags?

If my custom field (called target) was say filled with:

4.7, 4.6, 4.5

Then would that work somehow?

Offline

#11 2019-04-18 12:15:56

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Can I narrow searches to only articles with certain tags?

philwareham wrote #317682:

If my custom field (called target) was say filled with:

4.7, 4.6, 4.5...

Then would that work somehow?

Yes, but you’d need to eventually add 4.8 etc when released. For every working plugin…

Offline

#12 2019-04-18 12:23:39

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Can I narrow searches to only articles with certain tags?

Oh, of course ? – but then again plugins would need to be individually verified against new Textpattern releases anyway so maybe that isn’t such a big problem.

The best route would be to do as you suggest though, and assume plugins are compatible with new releases unless we tag them as not compatible. Less work to maintain.

I think it’s pretty important that the new plugins site lists a plugin’s compatibility and searches can be filtered by Textpattern version you are using.

Not sure how to proceed. This is proving more complex that I had originally thought!

A lot of this transfers to the planned themes website too, as the plugins and themes sites share a lot of common code.

Offline

Board footer

Powered by FluxBB