SOLVED: Code element displays error

Bricks Version: 1.3.7
Browser: Chrome 90
OS: macOS / Windows / Linux / etc.
URL: ALQUILER DE BARCO SIN LICENCIA EN MENORCA – Alquiler de barcos y lanchas en Menorca – Ciutadella y Fornells

I think it’s because the loop is empty, bye the message it displays…

I’ve removed the line 154 from /bricks/includes/elements/code.php

beacuse I need to deliver that site…

Hope is fixed in next update:

Hey,
What is inside of your code element?

Hi,

First I have created a bricks template with a query. But I leave the query empty, so from a parent with a defined query and the filter you provide, I can call that template for different queries.
so in the parent query there is that cade

<?php

	global $wp_query;

	$backup = $wp_query ;
	$wp_query =  new WP_Query(array(
  	"post_type" => "bcbs_boat",

    'meta_query'	=> array(
      'relation'		=> 'OR',
      array(
        'key'	 	=> 'without_licence',
        'value'	  	=> "1",
        'compare' 	=> 'NOT LIKE',
      ),
      array(
        'key'	 	=> 'without_licence',
        'value'	  	=> "1",
        'compare' 	=> 'NOT EXISTS',
      ),
      
    ),
		//'meta_value'	=> "1",
  ));

	//list barcos sin query
	echo do_shortcode('[bricks_template id="3377"]');

	$wp_query =  $backup;

?>

Probably the error is because the query is just enabled and didn’t set any parameters. So the error display “query_vars is undefined”…

thanks

Hello @salwebs

And where do you set the query_vars filter?

  • that line is empty.
  • The logic is correct. You could set a query loop with some standard configuration like query the bcbs_boat posts and then use the filter bricks/posts/query_vars to fine-tune it on each post. I wouldn’t use the code you posted in your last reply.

Bottom line, it seems it is not a Bricks bug but we would like to help you to find the root cause of the PHP notice.

inside the “empty loop” template.


The “merge vars” has this content:

<?php


  add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings , $element_id) {
    if ( $element_id === 'ndbhii' ) {
		global $wp_query;
		
    return wp_parse_args( $this->query_vars, $wp_query->query );
      
  }

    return $query_vars;
}, 10, 3 );

add_filter( 'bricks/posts/merge_query', function( $merge, $element_id ) {


  



  if ( $element_id === 'bvpuao' ) {

		
    return true;
  }

  return $merge;
}, 10, 2 );


?>

“ndbhii” is the container loop id.

I’ll try

153 sorry. “ini_set(‘display_errors’, 1);”

Any news about that?

Hello @salwebs

Sorry for the late reply.

There is one error in this line: $this->query_vars do not exist in that context. You should use $query_vars.