• Hi all. Since WordPress makes ultimately a blog-surrounding there are some serious limitations to it. I would like to have a ‘split’ title in which each part individually works like a tag, for example “Bandname”, “album title”, “label”, “format”, “year of release” (album reviews ‘blog’). If someone clicks on the band-name, (s)he gets all posts of that band, the same goes for label, year, format. Since this seems not possible I thought of a rather simple sollution: search only in post titles. That way the result would not list a post in which some band is named in the content of the post (i.e. as comparison). I have searched the forums, support pages, other websites, but so far I haven’t found a tag or plugin that offers this feature. Does anyone know one (or how to make one into working) like this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I use posts as a rudimentary calendar. I assign them the category of ‘calendar.’ They contain a sortable event date, a date in words and the name of the event. I sort on the category and the numeric date

    20071122 November 22, 2007 Thankgiving Day
    20071225 December 25, 2007 Christmas Day

    I split off the numeric date and discard it using the space as the character I split on. Here’s my code. Warning! Regular Expressions Ahead! 😉

    $postslist = query_posts('cat=7&order=DESC');
    foreach ($postslist as $post) :
       setup_postdata($post);
       $mypost_title = the_title('','',false);
       $datewords = preg_split("/[\s]+/", $mypost_title);
       echo $datewords[1] . " " . $datewords[2] . " " . $datewords[3];
      the_excerpt();
      echo "";
    endforeach;

    Your need is a little more complicated. It seems you’d need to parse your post titles as I have and then while they are looping do a match and only display those post titles that contain the band name. You’d match on the indexed array element that corresponded to the band name. You might want to use a different delimiting character in your raw titles than a space. Then when you go to display the titles, you could strip it out.

    Hope this helps. I’m new to programming WP so someone may come up with a more elegant or efficient solution. I haven’t yet done any direct querying of the db using SQL so I can’t offer advice on that. I’ve done it in other languages and systems but not here yet. That’s my next step! 😉

    Codecottage

    Thread Starter Roy

    (@gangleri)

    Wow, I’ve been bumping my brains with WP for a little over half a year (without understanding much of programming it), but your post almost breaks it! Fortunately the need to make your idea workable for my wish on short terms is not as high since tags are added to WP 2.3.1 (I now have categories with musical styles (i.e.) and tags for band- and labelnames, which works nice). For a more “elegant” sollution I might still want to use the search function, so thanks for your starter.

    Gangleri,

    I actually made a crucial error in my code. I thought that the date (Ex. 20070831) I was pulling from the front of the title was numeric and therefore sortable. It’s not! It’s a string. But I investigated further and found that I could use the menu order field. This is available for pages not posts.

    Here are some ideas of how you might do what you’re attempting.

    1.Use pages instead of posts.(You may be doing this.)
    2.Use the custom fields at the bottom of the page editing page. These consist of name/value pairs. You can store great little nuggets of data about your pages there! Really cool. Is this what you mean by tags?
    3. Explore using SQL queries. They allow you to get right at those nuggets of data you need. The API functions, nice as they are (like “the_title()”) don’t expose all the fields in the database tables. The SQL language isn’t hard if you have programmed in PHP, JavaScript or ASP.
    4. If you go the SQL route, get to know the structure of the database by using PHP MyAdmin if your hosting service provides that. The custom fields, for example, live in the wp_postmeta table whereas most of the other page stuff lives in the wp_posts table.

    I’m having a lot of fun with WP recently. At first I felt like I was also knocking my head against a brick wall but now I’m starting to see that it is more workable. I’ve got 2.3.1 too.

    Enjoy!

    Codecottage

    Thread Starter Roy

    (@gangleri)

    Hi Codecottage. Besides that I probably won’t be able to reproduce what you suggest, it is also impossible to achieve for the simple reason that I have 1500 posts that I would have to make into pages. In any case, 2.3.1 has “tags” which are not the custom fields, but actually just categories with a different name. A category can now be musical style, a tag a bandname, so I have two ways of marking a review for navigation which works fine and no longer requires editing the search function (however I would like the search function to recognise letters with accents (search a and also find á), but this is an entirely different subject).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search post titles only’ is closed to new replies.