Reputation: 7102
I am trying to search the wordpress posts in my database, that match a string.
However i want to get the rows that have the matching words in them as a plain text, but not the ones that have the word embedded inside a link.
For example, if a post has the following text in 'wp_posts' table of database:
'This is a Test page: <a href="http://localhost/test-page">About Test</a>'.
And i search for the word 'about' in my custom query:
SELECT * FROM `wp_posts` WHERE post_content like '%about%';
so i am getting the above post as the result. Is there a way i can ignore the posts that have the search string embedded inside a link, and fetch other posts which have the search string as part of a normal string?
I tried a REGEX query, with no luck:
SELECT * FROM `wp_posts` WHERE post_content REGEXP '[[:<:]]about[[:>:]]';
Upvotes: 1
Views: 180
Reputation: 601
May be this :
SELECT * FROM `wp_posts` WHERE post_content LIKE '%about%' AND post_content NOT REGEXP '>[^>]*about[^<]*<';
Upvotes: 3
Reputation: 10573
Try this
SELECT * FROM `wp_posts` WHERE post_content REGEXP '^[^<>]+about';
Here is the Fiddle
Upvotes: 1
Reputation: 3109
in sqlfiddle it works fine!
http://sqlfiddle.com/#!2/f1697/2
Create script
CREATE TABLE supportContacts
(
test longtext
);
INSERT INTO supportContacts(test) VALUES ('This is a Test page: <a href="http://localhost/test-page">About Test</a>')
Select
select * from supportContacts where test like '%about%'
Upvotes: 0