Last active
October 28, 2024 19:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); |
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
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 );