List all posts not containing a given character in excerpt? (5 posts)

  1. symmetrium
    Posted 4 years ago #

    Hi, I have searched the web without being able to find an answer to the following problem:

    I need to make wordpress list all posts which do not contain the "|" character in the post excerpt.

    For example in google search syntax that would be equivalent to putting a minus before a word to exclude the word from results. Briefly put, i need a snippet that would exclude all such posts from the wordpress loop on the index page.

    I could not figure out what the wordpress search syntax for this would be, or the query string that could return a similar result.

    Any help would be largely appreciated, thank you in advance : ))

  2. keesiemeijer
    Posted 4 years ago #

    It can be done with get_posts or a query posts and http://php.net/manual/en/function.preg-match.php (not so easy). But why not give all the posts with an exerpt with "|" in them a custom field and query the posts for that custom field (easy).


    query post for custom field: http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters

  3. symmetrium
    Posted 4 years ago #

    Thank you for your reply, keesiemeijer :)

    Yes, the custom field solution seems fine but the problem is that in the specific application I'm developing, logged in users users modify the excerpt and insert a "|" to tag them for a certain purpose. I've used scribu's front-end editor for that functionality and i guess I would need to modify the plugin to check each time whether a "|" was input in order to insert the proper value in that custom field. That might get too messy for me : ))

    On the other hand, a solution involving get_posts and query posts would be great (my guess is that strpos() could also be used instead of preg_match()?) but I couldn't figure out how to integrate those to that effect... I mean, what would the query string look like?

  4. keesiemeijer
    Posted 4 years ago #

    I don't think it is possible to query posts based on them having an excerpt or not. Maybe it is possible with a custom query

  5. symmetrium
    Posted 4 years ago #

    Well I guess I'll have to figure out another way around this.. thanks anyway! :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.