Support » Themes and Templates » Query pages by partial title match

  • Hi,

    I’m wondering if there’s a way to query against pages matching a specific title pattern with the built in functions.

    Say I have a bunch of pages that begin with an unique word I want to build a list of them.

    I’ve spent a lot of time looking at the query_posts and WP_Query options documentation and related forum posts with no avail. Seems the only way to do it is with a match against the specific slug but I’m looking for something more like this which I know doesn’t work although hopefully it gets the point across:

    I only need the title and permalink, so I have though about using wp_page_menu or wp_list_pages and passing then extracting only what I need out of it, but this seems like an ugly hack and pretty expensive if there’s an easier way.

    Any thoughts on how to achieve this type of result?


Viewing 3 replies - 1 through 3 (of 3 total)
  • If you want a temporary fix, the way that I’d do it would be to use the function get_posts('numberposts=-1'); to put all of your post data into an array, and then run some tests on it to see if it matches what you want.

    Wouldn’t it just be simpler to use the search though?

    Actually, the fix that I suggested was a “post” fix, which wouldn’t help you in your case, and you seemed to have already thought about using the list_pages function, which would be my suggestion.

    Hi Wex,

    Thanks for the responses.

    I did just end up doing a query to get all pages, then just put the data into an array and working with it from there. Not quite as efficient as I would like, but it works better than no solution 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Query pages by partial title match’ is closed to new replies.