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
# include the categories or tags
% wpgrep ... --categories
% wpgrep ... --tags
# specify a template for the results
% wpgrep ... --template '%T'
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 --categories
or --tags
, the returned rows are annotated with relationship information. The categories
and tags
keys have array reference values with lists of term names. The terms
keys is a hash with more term information. Dump it and inspect it if you want to play with it. Furthermore, the returned rows are reduced to the rows that have the specified categories if you give those options values.
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)!
--category
With no value, each returned row has category and tag information added to it.
With a category names, the returned rows are reduced to those having that category. No parent relationships are examined.
You may specify this multiple times. Any row having any of the specified categories is returned. If you specify
--categories_and
, each row must have all of the categories.--categories_and
If you specify
--categories_and
, each row must have all of the categories.-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
.--tags
With no value, each returned row has category and tag information added to it.
With a tag name, the returned rows are reduced to those having that tag.
You may specify this multiple times. Any row having any of the specified tags is returned. If you specify
--tags_and
, each row must have all of the categories.--tags_and
If you specify
--tags_and
, each row must have all of the tags.--template
Specify the sprintf-style template to format the row.
-u, --user
The MySQL user. You might want to set up a special read-only user for this tool.
Template
Most template items map directly onto the columns from wp_posts.
%A post_password
%a post_author
%C comment_count
%c post_content
%D post_modified
%d post_date
%e post_excerpt
%f post_content_filtered
%G post_modified_gmt
%g post_date_gmt
%i ID
%K categories
%k tags
%m post_mime_type
%n post_name
%o menu_order
%P ping_status
%p post_parent
%R newline
%S comment_status
%s post_status
%T post_type
%t post_title
%U guid
%Z pinged
%z to_ping
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 © 2013-2015, brian d foy <bdfoy@cpan.org>. All rights reserved.
You may redistribute this under the same terms as Perl itself.