MT:Entries not returning results correctly on search page

170 views Asked by At

I'm building out a search results page within a blog. I've rewritten the URL so that going to:

/blog/tag/foo

will return a search results for foo.

In the template, I'd like to return a listing of all the posts that are tagged with 'foo', so I've made an MT:Entries block that starts:

<mt:Entries tag="<$mt:SearchString$>">  

but it returns no results. However, placing on the page outputs 'foo' just fine.

So I tried this:

<mt:Entries tag="foo">

and it returns all results correctly that are tagged with foo. I'm not seeing a reason why the other one should work -- any ideas?

2

There are 2 answers

1
François Nonnnemacher On BEST ANSWER

You cannot use a tag as a parameter value. You'll have to pass it via a variable, like so:

<mt:setvarblock name="q"><$mt:SearchString$></mt:setvarblock>
<mt:Entries tag="$q">
0
Beau Smith On

The reason why <mt:Entries tag="foo"> worked is because you are telling Movable Type to explicitly grab the entries tagged "foo". This is how you should do it in most templates, however the Search Results system template is different.

While the example Francois offers should work, it's not the intended method to get "tag search" results in the Search Results system template.

In the Search Results template, instead of the <mt:Entries> block tag use the <mt:SearchResults> block tag.

You code should look something like this:

<mt:SearchResults>
    <mt:IfTagSearch>
        <!-- Template tags for "tag search" results -->
    </mt:IfTagSearch>
    <mt:IfStraightSearch>
        <!-- Template tags for "text search" results -->
    </mt:IfStraightSearch>
</mt:SearchResults>

For a more detailed example, take a look at the code in the default Search Results template in the "Classic Blog" template set (which ships with Movable Type) and modify the working (and tested) code.