How can I check for a word in wordpress post?

7 replies
Hi,

How can I check for a word in a wordpress post?

I would like the code to check for the tags [hidepost] and [/hidepost] and to display a certain text if the tags are found.

How can I do that?
#check #post #word #wordpress
  • Profile picture of the author Fenshon
    I think you are looking for a sort of find and replace function in wordpress post right?
    Signature
    {{ DiscussionBoard.errors[8285535].message }}
    • Profile picture of the author MindReality
      Originally Posted by Fenshon View Post

      I think you are looking for a sort of find and replace function in wordpress post right?
      Not replace, just find. And the find has to take place purely in the code itself, not as a search box.

      To explain it a bit further...


      I would like to know what code can I use to do this:

      Check whether the post content contains the Text "This page has a recommended product."

      And then display a link, For E.g. "www.domain.com" under the post content.

      Is it possible to do something like that?
      Signature
      Discover The Greatest Secrets Of The Mind And Reality That Will Get You Anything You Desire, Almost Like Magic! Visit: http://www.MindReality.com
      {{ DiscussionBoard.errors[8285559].message }}
      • Profile picture of the author MindReality
        I am trying to search for a word in a post. The code has to look through the entire post content to find whether that word exist in it, and to display a text that says so.

        What I am looking to do is:

        Programatically do something like:

        if this condition is true > then perform the following action

        How can this be done?
        Signature
        Discover The Greatest Secrets Of The Mind And Reality That Will Get You Anything You Desire, Almost Like Magic! Visit: http://www.MindReality.com
        {{ DiscussionBoard.errors[8285688].message }}
        • Profile picture of the author MindReality
          Will this shortcode work?

          Code:
          function hidepost_shortcode() {
           
              return '<div align="center"><b>Wait, this is just PART of the secrets revealed... There is MUCH vital information you are missing... <a href="http://www.mindreality.com/view.html">Click Here to View the HIDDEN PART!</a></b></div>';
           
          }
          add_shortcode('hidepost', 'hidepost_shortcode');
          Or should I be using a filter?
          Signature
          Discover The Greatest Secrets Of The Mind And Reality That Will Get You Anything You Desire, Almost Like Magic! Visit: http://www.MindReality.com
          {{ DiscussionBoard.errors[8287290].message }}
  • Profile picture of the author alfa_375
    use pregmatch() to find the text and put condition to what ever you want to do.
    {{ DiscussionBoard.errors[8289238].message }}
    • Profile picture of the author MindReality
      Kael41 suggested:

      "As a programming overlay, this is twofold: one, you would need a function which calls into the mysql db to "search" the post field for that specific post in the tablespace to see if the word apple exists. Then, you would need a call in the php code itself to call that function which checks the tablespace and then outputs that the term "apple" exists. Makes sense?"

      This was something I thought about at first. Can someone help me with an example of the specific codes I need to use?
      Signature
      Discover The Greatest Secrets Of The Mind And Reality That Will Get You Anything You Desire, Almost Like Magic! Visit: http://www.MindReality.com
      {{ DiscussionBoard.errors[8291612].message }}
  • Profile picture of the author otfromtot
    I think this has a search option without having to replace WP – Suchen und Ersetzen (de) (Plugin) | bueltge.de [by:ltge.de]
    I'm not sure if you wanted to search from the site itself or 'behind the scenes'
    {{ DiscussionBoard.errors[8318003].message }}

Trending Topics