Site logo

Archived topic

Error on option_generate_blog_settings with is_search()

9 replies · Started by Jeroen on January 25, 2022

Viewing posts 1–10 of 10

Hi,

I use the following code to customize my search results (based on https://docs.generatepress.com/article/option_generate_blog_settings/)

//different search page settings
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
    if ( is_search() ) {
	$options['read_more_button'] = true;
	$options['date'] = false;
	$options['categories'] = false;
	$options['tags'] = false;
	$options['comments'] = false;
    $options['infinite_scroll'] = true;
	$options['infinite_scroll_button'] = true;
	$options['masonry_load_more'] = 'More search results';
	$options['post_image'] = false;
	$options['post_image_position'] = 'post-image-above-header';
	$options['post_image_alignment'] = 'post-image-aligned-center';
	$options['column_layout'] = false;
	$options['featured_column'] = false;
	$options['masonry'] = false;
    }
  
    return $options;
}
//end different search page settings

This code is placed in my custom plugin.
But unfortunately it gives an error:
Notice: is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /var/www/vhosts/consiltant.com/test.consiltant.com/wp-includes/functions.php on line 5663

Any idea on how to fix this?

Hi!

Thanks.

Pluginception / creating a new plugin didn't work.

Code snippets did work :-)

Are there also other ways of changing the layout of the search page (without using filter). For example by using the generate_press elements?

What exactly are you trying to change?

My archive/blog pages are using a column layout (2 columns) for the overview pages. This is set via the customizer blog settings. I use 'content templates' to further modify the design of the archive/blog pages.

For my search page I do not want to use the column layout. Therefore I use the code below to alter the 'blog settings' for the search page.

add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
    if ( is_search() ) {
	$options['read_more_button'] = true;
	$options['date'] = false;
	$options['categories'] = false;
	$options['tags'] = false;
	$options['comments'] = false;
	$options['infinite_scroll'] = true;
	$options['infinite_scroll_button'] = true;
	$options['masonry_load_more'] = 'More search results';
	$options['post_image'] = false;
	$options['post_image_position'] = 'post-image-above-header';
	$options['post_image_alignment'] = 'post-image-aligned-center';
	$options['column_layout'] = false;
	$options['featured_column'] = false;
	$options['masonry'] = false;
    }
  
    return $options;
}

Is it possible to change the blog layout settings without use of filters / PHP-code, for example by 'content template' elements?

I have created a 'content template' for the search page, which works perfectly. But this does not change the column layout.
In the end I want to have 1 column (full width).

Hi there,

currently no - you have top use the option_generate_blog_settings to change columns, masonry etc

ok, thanks

In a future update GB will have a query loop block, and GP will be able to support that to create both the content template and the grid layout :)

Awesome!

:) Glad to be of help

This archived topic is closed to new replies.