[wp-hackers] meta query crashing database

Steve Taylor steve at sltaylor.co.uk
Wed Aug 31 23:10:11 UTC 2011


I'm trying to build a query. I have a CPT, "campaigns", which is
related to one or more "issues" (also a CPT).

The relationship is managed by a custom meta box on the campaigns edit
screen, you select the issues. It stores one or more entries in the
postmeta table, each having the ID of the issue.

What I need to do is, for the single campaign template, grab a list of
"related" campaigns. So I need to grab all other campaigns that are
related to any of the issues that the campaign being viewed is related
to. The dump of the WP_Query arguments, for campaign ID 851, with a
bunch of related issues, is this:

Array
(
    [post_type] => campaign
    [posts_per_page] => -1
    [post__not_in] => Array
        (
            [0] => 851
        )
    [meta_query] => Array
        (
            [relation] => OR
            [0] => Array
                (
                    [key] => _slt_issues
                    [value] => 185
                )
            [1] => Array
                (
                    [key] => _slt_issues
                    [value] => 194
                )
            [2] => Array
                (
                    [key] => _slt_issues
                    [value] => 193
                )
            [3] => Array
                (
                    [key] => _slt_issues
                    [value] => 187
                )
            [4] => Array
                (
                    [key] => _slt_issues
                    [value] => 191
                )
            [5] => Array
                (
                    [key] => _slt_issues
                    [value] => 189
                )
            [6] => Array
                (
                    [key] => _slt_issues
                    [value] => 186
                )
            [7] => Array
                (
                    [key] => _slt_issues
                    [value] => 190
                )
            [8] => Array
                (
                    [key] => _slt_issues
                    [value] => 188
                )
            [9] => Array
                (
                    [key] => _slt_issues
                    [value] => 192
                )
        )
)

This crashes the database in quite a severe way, and I've bothered my
sysadmin for a reboot one too many times now experimenting with it!

Can anyone see anything obviously wrong? There's only ten or so
campaigns in the system, and about the same amount of issues. Is it
just the number of parts to the meta_query? Is it related to the fact
that _slt_issues may have multiple entires in the postmeta table for
the same campaign? Is there any feasible way of doing this query?

Many thanks for any thoughts,

Steve Taylor


More information about the wp-hackers mailing list