How can I search for a wordpress post in mysql?

6 replies
How can I search for a wordpress post in mysql database?
#mysql #post #search #wordpress
  • Profile picture of the author Dan Grossman
    Code:
    SELECT * FROM wp_posts WHERE post_content LIKE '%searchterm%'
    Signature
    Improvely: Built to track, test and optimize your marketing.

    {{ DiscussionBoard.errors[7028915].message }}
    • Profile picture of the author MindReality
      So if I want to search for a post title that contains the term "Reality Creation".

      Is this the query?

      SELECT * FROM `wp_posts` WHERE post_title LIKE 'reality creation'
      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[7029387].message }}
  • Profile picture of the author Dan Grossman
    Code:
    SELECT * FROM wp_posts WHERE post_title = 'reality creation'
    You can use a DESCRIBE query to get a list of the columns in a table.

    Code:
    mysql> DESCRIBE wp_posts;
    +-----------------------+---------------------+------+-----+---------------------+----------------+
    | Field                 | Type                | Null | Key | Default             | Extra          |
    +-----------------------+---------------------+------+-----+---------------------+----------------+
    | ID                    | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
    | post_author           | bigint(20) unsigned | NO   | MUL | 0                   |                |
    | post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
    | post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
    | post_content          | longtext            | NO   |     | NULL                |                |
    | post_title            | text                | NO   |     | NULL                |                |
    | post_excerpt          | text                | NO   |     | NULL                |                |
    | post_status           | varchar(20)         | NO   |     | publish             |                |
    | comment_status        | varchar(20)         | NO   |     | open                |                |
    | ping_status           | varchar(20)         | NO   |     | open                |                |
    | post_password         | varchar(20)         | NO   |     |                     |                |
    | post_name             | varchar(200)        | NO   | MUL |                     |                |
    | to_ping               | text                | NO   |     | NULL                |                |
    | pinged                | text                | NO   |     | NULL                |                |
    | post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
    | post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
    | post_content_filtered | longtext            | NO   |     | NULL                |                |
    | post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |
    | guid                  | varchar(255)        | NO   |     |                     |                |
    | menu_order            | int(11)             | NO   |     | 0                   |                |
    | post_type             | varchar(20)         | NO   | MUL | post                |                |
    | post_mime_type        | varchar(100)        | NO   |     |                     |                |
    | comment_count         | bigint(20)          | NO   |     | 0                   |                |
    +-----------------------+---------------------+------+-----+---------------------+----------------+
    23 rows in set (0.00 sec)
    Signature
    Improvely: Built to track, test and optimize your marketing.

    {{ DiscussionBoard.errors[7029410].message }}
    • Profile picture of the author eswariseo
      Whatever string you are looking for, substitute the terms your search string, in the SQL question below.
      SELECT id, post_title, post_status, post_type, SUBSTR(post_content, LOCATE('your search string', post_content) -1, 100) FROM wp_posts WHERE locate('your search string', post_content) > 0
      {{ DiscussionBoard.errors[7029444].message }}
      • Profile picture of the author MindReality
        I found out how to do it.

        I just go to my blog database in phpMyAdmin

        Click on search

        Type in my search term.

        Find all words.

        Inside table wp_posts

        Inside column post_title
        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[7029881].message }}
  • Profile picture of the author john8954
    SELECT ID FROM 'wp_posts' WHERE 'post_content' LIKE '%embed%' Use query to know your post. if not get good ans then go to word press blog.
    Signature

    {{ DiscussionBoard.errors[7040405].message }}

Trending Topics