ERROR: Plugin fails with custom wp_query filter
-
I’ve set up a connection between ‘posts’ and custom post type ‘facts’ using this code:
function my_connection_types() { p2p_register_connection_type( array( 'name' => 'posts_to_facts', 'from' => 'post', 'to' => 'fact', ) ); } add_action( 'p2p_init', 'my_connection_types' );
Yet, when I edit a post (or fact) it throws this error:
WordPress database error: [Operand should contain 1 column(s)]
and this SQL query in the admin edit screen where the select box should be (I assume):SELECT wp_posts.ID, wp_extended_table.*, wp_p2p.* FROM wp_posts LEFT JOIN wp_extended_table ON wp_posts.ID = wp_extended_table.id INNER JOIN wp_p2p WHERE 1=1 AND wp_posts.post_type IN ('post') AND (wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft') AND ( wp_p2p.p2p_type = 'posts_to_facts' AND wp_posts.ID = wp_p2p.p2p_from AND wp_p2p.p2p_to IN ( SELECT wp_posts.ID, wp_extended_table.* FROM wp_posts LEFT JOIN wp_extended_table ON wp_posts.ID = wp_extended_table.id WHERE 1=1 AND wp_posts.ID IN (58) AND wp_posts.post_type IN ('fact') AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC ) ) ORDER BY wp_posts.post_date DESC
At first blush, it looks like posts-2-posts is missing the
ON
statement for the inner join… but I could be jumping the gun…I have a two filters added to wp_query:
posts_join
to append all queries with aleft join
to an extended meta table, andposts_fields
which adds the joined fields. This works great until I try to use Posts-2-Posts.Any thoughts?
EDIT: Perhaps its the
posts_fields
that is throwing this off since it seems posts_to_posts wants to searchIN
ID only, and theposts_fields
filter is giving it other info it didn’t ask for… Seems like the fix might be to process the results to extract the ID after the query, not assuming the ID will be the only thing returned by the query… But I’m just guessing here…
- The topic ‘ERROR: Plugin fails with custom wp_query filter’ is closed to new replies.