Possible conflict between Events+ and CustomPress custom template

I have set up the Events + plugin on my site but now I want to see my custom data page but this fatal error appears:

Fatal error: Call to a member function is_main_query() on a non-object in /home/einstein/public_html/wp-content/plugins/events-and-bookings/lib/default_filters.php on line 122

Deactivating Events + renders my custom page with data in a correct manner, but when Events + comes becomes active, it does not work?

Since I need both CustomPress and Events+ active, what can I do to avoid this conflict? Do you need to see my custom page source code? How can I fix that error?

Thanks in advance for the help :smiley:.

  • Vaughan
    • Support/SLS MockingJay

    Hi @Carlos Ramos,

    I've never come across that error before, but that line is part of the categories function for ordering.

    Can you post a screenshot of your custom post type settings. Also the loop/Query that you are using on your custom page template?

    I'm going to ask the developer for some feedback on this for you.

    Thanks

  • Carlos Ramos
    • Design Lord, Child of Thor

    Hello, @Vaughan,

    Here is the code I use to make the query:

    $args = array (
    	'post_type' => 'tarea',
    	'post_status' => 'publish',
    	'paged' => $paged,
    	'posts_per_page' => 16,
    	'ignore_sticky_posts'=> 1,
    	'orderby'=>'ct_Fecha_de_e_datepicker_715e',
    	'order' => 'DESC',
    	'meta_query'=> array(
    		array(
    			'key' => 'ct_Nivel_selectbox_a3aa',
    			'value' => $nivel,
    		),
    		array(
    			'key' => 'ct_Grado_selectbox_da5f',
    			'value' => $grado,
    		),
    	),
    );
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query($args);

    Then just the normal loop:

    if ( $wp_query->have_posts() ) :
        while ( $wp_query->have_posts() ) : $wp_query->the_post();

    As for the screenshot, what is the info you need exactly or where can I get those custom post type settings (because the "Edit Custom Type" page is kinda large)?

    I hope that was the information needed. If not, drop a line and I will be back at you.

    Regards,
    Carlos.

  • Carlos Ramos
    • Design Lord, Child of Thor

    @Vaughan,

    I commented out the order and orderby arguments in $args, with no luck. After that, I started commenting every possible option in the array but it seems that, as soon as one property is set in the query, the code fails.

    It only executed without error when $args was completely empty (and therefore no query was made).

    So, yes, the error is in the query as you say, but I do not see how come the Events + gets into the mix (but it definitely invites itself into the query or something).

    Regards.

  • Carlos Ramos
    • Design Lord, Child of Thor

    Hello again, @Vaughan,

    It is working now. After some research, I stumbled upon the following solution:

    $temp = $wp_query; // assign ordinal query to temp variable for later use
    //$wp_query = null;
    $wp_query = new WP_Query($args);

    That is, only to comment out the null assignment. However, that seems to be related with a bad practice of some kind, although I did not research further.

    The original resource is here. The Events + and the custom types seem to be working for now, so case closed :smiley:.

  • Vladislav
    • Dead Eye Dev

    Hello,

    Thank you very much for the update. Setting the $wp_query global to null isn't really advisable - actually, IMHO, the globals, especially the WP core ones, are best left alone at all times if at all possible. However, if you really, really need to override the $wp_query global, please ensure that you're overriding it with a WP_Query instance.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.