NAME
wpgrep - Search through a WordPress database directly
SYNOPSIS
# search by SQL pattern
% wpgrep --host ... --user ... --like '%Amelia%'
# search by Perl pattern
% wpgrep --host ... --user ... --regex '\bAmelia(?!Foo)'
# search by arbitrary code
% wpgrep --host ... --user ... --code Some::Module::subroutine
# or combine them
% wpgrep --host ... --user ... --like '%Amelia%' --regex '\bAmelia(?!Foo)' --code Some::Module::subroutine
DESCRIPTION
I wanted a tool for complex searches of WordPress posts in my own installations. This is it. I can search by an SQL pattern, a Perl regular expression, or a any code I care to run on the values.
If you specify --like
, it limits the returned rows to those whose post_title
or post_content
match that argument.
If you specify --regex
, it filters the returned rows to those whose post_title
or post_content
satisfy the regular expression.
If you specify --code
, it filters the returned rows to those for which the subroutine reference returns true. The coderef gets a hash reference of the current row. It's up to you to decide what to do with it.
These filters are consecutive. You can specify any combination of them but they always happen in that order. The --regex
only gets the rows that satisfied the --like
, and the --code
only gets the rows that satisfied --like
and --regex
.
Options
-c, --code
The fully-qualified name (e.g. Some::Module::subroutine) of a subroutine to run on each record. The program loads that module for you.
Be careful! This allows someone to run any code they like (and that's the point)!
-d, --db, --database
The database name. This is the
DB_NAME
in your wp-config.php.-h, --host
The database host. This defaults to
localhost
.-l, --like
An SQL pattern suitable for a LIKE argument. The regex applies to the
post_title
andpost_content
.See http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
-p, --password
The database password associated with the user and the source machine, if you need that.
--port
The MySQL port, if you aren't using the default.
-r, --regex
A Perl regex used to filter the results. The regex applies to the
post_title
andpost_content
.-u, --user
The MySQL user. You might want to set up a special read-only user for this tool.
TO DO
SEE ALSO
SOURCE AVAILABILITY
This source is in Github:
http://github.com/briandfoy/wordpress-grep/
AUTHOR
brian d foy, <bdfoy@gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2013, brian d foy, All Rights Reserved.
You may redistribute this under the same terms as Perl itself.