Skip to content

Instantly share code, notes, and snippets.

@MarieComet
Last active October 28, 2024 19:12
Show Gist options
  • Select an option

  • Save MarieComet/7ff001750a5e8a0ec6a724fcb4c6ccdd to your computer and use it in GitHub Desktop.

Select an option

Save MarieComet/7ff001750a5e8a0ec6a724fcb4c6ccdd to your computer and use it in GitHub Desktop.
Allow to select multiple post types as query source in Elementor Posts widget
<?php
function elementor_posts_widget_multiple_post_types( $element, $args ) {
$element->update_control(
'posts_post_type', // control ID
[
'type' => Elementor\Controls_Manager::SELECT2,
'multiple' => true,
]
);
}
add_action( 'elementor/element/posts/section_query/after_section_end', 'elementor_posts_widget_multiple_post_types', 10, 2 );
@nodex4
Copy link

nodex4 commented Apr 14, 2022

is it enough if i addd this to my theme's function.php file or should I make a new one?

@MarieComet
Copy link
Author

@TroopekYT yes, you don't need to create a new theme.

@nodex4
Copy link

nodex4 commented Apr 14, 2022

Thanks a lot it worked!

@nodex4
Copy link

nodex4 commented Jul 8, 2023

any chance you could reqrite this for the new loop grid?

@MarieComet
Copy link
Author

Hi @nodex4.

What is the new loop grid please ?
Any doc ?

@kinokeo
Copy link

kinokeo commented Jul 23, 2023

@MarieComet - I assume Nodex means this: https://elementor.com/help/loop-grid/

This would be very helpful for me too.

@nodex4
Copy link

nodex4 commented Aug 8, 2023

Exactly, i mean that one right there.

@EricJammin
Copy link

+1 for extending this to the loop grid builder, would be super helpful!

@cheyennecenk
Copy link

Loop Carousel:
function elementor_loopcarousel_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-carousel/section_query/after_section_end', 'elementor_loopcarousel_widget_multiple_post_types', 10, 2 );

Loop Grid
function elementor_loopgrid_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-grid/section_query/after_section_end', 'elementor_loopgrid_widget_multiple_post_types', 10, 2 );

@artvendor
Copy link

Loop Carousel: function elementor_loopcarousel_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-carousel/section_query/after_section_end', 'elementor_loopcarousel_widget_multiple_post_types', 10, 2 );

Loop Grid function elementor_loopgrid_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-grid/section_query/after_section_end', 'elementor_loopgrid_widget_multiple_post_types', 10, 2 );

Thanks, This code works perfectly

@Miss-NewYork
Copy link

Loop Carousel: function elementor_loopcarousel_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-carousel/section_query/after_section_end', 'elementor_loopcarousel_widget_multiple_post_types', 10, 2 );

Loop Grid function elementor_loopgrid_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-grid/section_query/after_section_end', 'elementor_loopgrid_widget_multiple_post_types', 10, 2 );

This is fantastic, thank you!!!
Any chance this would work with the new live search widget as well?

@cheyennecenk
Copy link

Loop Carousel: function elementor_loopcarousel_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-carousel/section_query/after_section_end', 'elementor_loopcarousel_widget_multiple_post_types', 10, 2 );
Loop Grid function elementor_loopgrid_widget_multiple_post_types( $element, $args ) { $element->update_control( 'post_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/loop-grid/section_query/after_section_end', 'elementor_loopgrid_widget_multiple_post_types', 10, 2 );

This is fantastic, thank you!!! Any chance this would work with the new live search widget as well?

Sure! Try this:
function elementor_search_widget_multiple_post_types( $element, $args ) { $element->update_control( 'search_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/search/content_section_query/after_section_end', 'elementor_search_widget_multiple_post_types', 10, 2 );

@Miss-NewYork
Copy link

This is fantastic, thank you!!! Any chance this would work with the new live search widget as well?

Sure! Try this: function elementor_search_widget_multiple_post_types( $element, $args ) { $element->update_control( 'search_query_post_type', // control ID [ 'type' => Elementor\Controls_Manager::SELECT2, 'multiple' => true, ] ); } add_action( 'elementor/element/search/content_section_query/after_section_end', 'elementor_search_widget_multiple_post_types', 10, 2 );

I tried tweaking your previous code myself, but obviously messed up something - this snippet however works like a charm! Thank you SO much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment