The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Query pages by partial title match (4 posts)

  1. mlepisto
    Posted 6 years ago #


    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?


  2. Wex
    Posted 6 years ago #

    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?

  3. Wex
    Posted 6 years ago #

    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.

  4. mlepisto
    Posted 6 years ago #

    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 :-)

Topic Closed

This topic has been closed to new replies.

About this Topic