Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected conflict with custom queries #249

Open
codearachnid opened this issue Oct 2, 2012 · 2 comments
Open

Unexpected conflict with custom queries #249

codearachnid opened this issue Oct 2, 2012 · 2 comments
Labels

Comments

@codearachnid
Copy link

I ran into an interesting DB error:

WordPress database error: [Operand should contain 1 column(s)]

upon further review it turns out that the bug was being created by another plugin, Tri.be's The Event Calendar (side note: which I'm a dev for). We are doing a major overhaul of our plugin's query structure that will fix this issue down the line. In the interest of suggesting a clean way to prevent this from happening to older versions of our plugin or other plugins that might be cluttering WP_Query with custom fields, I submit this simple filter to ensure the nested select only has 1 column.

<?php

/**
 * Fix compatibility issues with The Event Calendar and Posts 2 Posts WordPress Plugins
 * Issue arrises with how nested select queries function when P2P expects a single column.
 */

function tribe_to_p2p_pre_get_posts( $query ){
    if(isset($query->_p2p_capture) && $query->_p2p_capture) {
        add_filter( 'posts_fields', 'tribe_to_p2p_setupFields', 20);    
    } else {
        remove_filter( 'posts_fields', 'tribe_to_p2p_setupFields', 20); 
    }
    return $query;
}
function tribe_to_p2p_setupFields( $fields ){
    global $wpdb;
    $fields = "{$wpdb->posts}.ID";
    return $fields;
}
add_action( 'pre_get_posts', 'tribe_to_p2p_pre_get_posts');

Source: https://gist.github.com/3815849

@sstasio
Copy link

sstasio commented Nov 15, 2012

Thanks for this solution, it was driving me crazy trying to figure this out.

@codearachnid
Copy link
Author

Glad it was able to help you out.

borkweb added a commit to the-events-calendar/the-events-calendar that referenced this issue Jun 2, 2015
This resolves a long-standing conflict with the Posts 2 Posts plugin which has historically required [a workaround](scribu/wp-posts-to-posts#249).

See: https://central.tri.be/issues/33288
borkweb added a commit to the-events-calendar/the-events-calendar that referenced this issue Jun 16, 2015
This resolves a long-standing conflict with the Posts 2 Posts plugin which has historically required [a workaround](scribu/wp-posts-to-posts#249).

See: https://central.tri.be/issues/33288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants