WordPress database error: [Operand should contain 1 column(s)]
WordPress Event Management, Calendars & Registration › Forums › Report A Bug › WordPress database error: [Operand should contain 1 column(s)]
This topic contains 0 replies, has 1 voice, and was last updated by carstenbach 11 years, 8 months ago.
-
AuthorPosts
-
March 23, 2013 at 2:57 am #4834
Hello!
Today I had a strange problem and after some hours of trial & error, failed debugging and searching, I’ll give my question to you.
Maybe someone knows.The setting is following:
Event-Organiser Plugin (just updated from 1.5.7 to 1.8.2) with post_type “event”
Client Plugin with post_type “staging”
Posts-2-posts Plugin (1.5.2) with a registered connection “events_with_stagings”, a many-to-one relation; many events belong to
one stagingNow I’m looping over some events and within theese loops, I want to get some information from the corresponding staging, i.E. the post_thumbnail or the_permalink.
For that I’m using a WP_Query like this, documented by the posts-2-posts Plugin over here// get connected staging from event
$p2p = new WP_Query( array(
'connected_type' => 'events_with_stagings',
'connected_from' => $event_post_object,
'nopaging' => true,
'suppress_filters' => false
) );
This query results in my above-mentioned SQL error, saying:
WordPress database error: [Operand should contain 1 column(s)]
The whole query looks like this
SELECT
wp_lofabi43_posts.*,
wp_lofabi43_p2p.*
FROM
wp_lofabi43_posts
INNER JOIN
wp_lofabi43_p2p
WHERE
1=1
AND
wp_lofabi43_posts.post_type
IN ('staging')
AND
(wp_lofabi43_posts.post_status = 'publish')
AND
(
wp_lofabi43_p2p.p2p_type = 'events_with_stagings'
AND
wp_lofabi43_posts.ID = wp_lofabi43_p2p.p2p_to
AND
wp_lofabi43_p2p.p2p_from
IN
(
SELECT
wp_lofabi43_eo_events.event_id,
wp_lofabi43_eo_events.event_id AS occurrence_id,
wp_lofabi43_eo_events.StartDate,
wp_lofabi43_eo_events.StartTime,
wp_lofabi43_eo_events.EndDate,
wp_lofabi43_eo_events.FinishTime,
wp_lofabi43_eo_events.event_occurrence,
wp_lofabi43_posts.ID
FROM
wp_lofabi43_posts
LEFT JOIN
wp_lofabi43_eo_events
ON
wp_lofabi43_posts.id = wp_lofabi43_eo_events.post_id
WHERE
1=1
AND
wp_lofabi43_posts.ID IN (4284)
AND
wp_lofabi43_posts.post_type
IN ('event')
AND
(
wp_lofabi43_posts.post_status = 'publish'
OR
wp_lofabi43_posts.post_author = 1 AND wp_lofabi43_posts.post_status = 'private'
)
ORDER BY
wp_lofabi43_posts.post_date DESC
)
)
ORDER BY
wp_lofabi43_posts.post_date DESC
At first I didn’t know, if it’s caused by the event-organiser, the posts-2-posts or some other. Plugin.
I checked other queries and found out, that querying from a “staging” to an “event” works fine and with no problem. Also all other Queries did there job, only queries for post_type “event” went wrong.I found out that a modified SQL Query with a reduced set a of columns inside the subquery results ok.
SELECT
wp_lofabi43_posts.*,
wp_lofabi43_p2p.*
FROM
wp_lofabi43_posts
INNER JOIN
wp_lofabi43_p2p
WHERE
1=1
AND
wp_lofabi43_posts.post_type
IN ('staging')
AND
(wp_lofabi43_posts.post_status = 'publish')
AND
(
wp_lofabi43_p2p.p2p_type = 'events_with_stagings'
AND
wp_lofabi43_posts.ID = wp_lofabi43_p2p.p2p_to
AND
wp_lofabi43_p2p.p2p_from
IN
(
SELECT
wp_lofabi43_posts.ID <------------ the last remaining column of the subquery
FROM
wp_lofabi43_posts
LEFT JOIN
wp_lofabi43_eo_events
ON
wp_lofabi43_posts.id = wp_lofabi43_eo_events.post_id
WHERE
1=1
AND
wp_lofabi43_posts.ID IN (4284)
AND
wp_lofabi43_posts.post_type
IN ('event')
AND
(
wp_lofabi43_posts.post_status = 'publish'
OR
wp_lofabi43_posts.post_author = 1 AND wp_lofabi43_posts.post_status = 'private'
)
ORDER BY
wp_lofabi43_posts.post_date DESC
)
)
ORDER BY
wp_lofabi43_posts.post_date DESC
But I couldn’t find any way to remove theese columns on the fly within a filter. My search led me to a similar problem with the “tribes events” Plugin found inside the issue tracker of the posts-2-posts Plugin, so I tried there solution, directly setting the posts_fields filter for my query, but with no look. It resulted in an infinite loop and no way to find the reason for that.
It seems very tricky to me, because my modified SQL statement from above is exactly the same, like the one wordpress produces after I filtered out all columns and replacing like this.function debug_p2p_pre_get_posts( $query ){
if(isset($query->_p2p_capture) && $query->_p2p_capture) {
add_filter( 'posts_fields', 'debug_p2p_setupFields', 10, 2);
} else {
remove_filter( 'posts_fields', 'debug_p2p_setupFields', 10, 2);
}
return $query;
}
function debug_p2p_setupFields( $fields, $query ){
global $wpdb;
$fields = "{$wpdb->posts}.ID";
return $fields;
}
add_action( 'pre_get_posts', 'debug_p2p_pre_get_posts');
Now I’m at an end and hope anyone could reproduce and / or solve this problem.
Any hints are very appreciated.best regards & good night
carstencarstenbach -
AuthorPosts