Created
February 24, 2023 01:41
-
-
Save captprice26/4000c413d2d469dd0987e83cc173734c to your computer and use it in GitHub Desktop.
This file contains 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
function influex_elm_cnd_get_post_types() { | |
$post_types = get_post_types( array( | |
'public' => true, | |
'publicly_queryable' => true, | |
)); | |
return $post_types; | |
} | |
add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) { | |
class Page_Template_Condition extends ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base { | |
public static function get_type() { | |
return 'archive'; | |
} | |
public static function get_priority() { | |
return 71; | |
} | |
public function get_name() { | |
return 'search_results_template'; | |
} | |
public function get_label() { | |
return __( 'Search Results Post Type' ); | |
} | |
public function check( $args ) { | |
$post_type = get_query_var('post_type'); | |
$post_type = $post_type ? $post_type : 'post'; | |
return is_search() && $post_type == $args['id']; | |
} | |
protected function _register_controls() { | |
$this->add_control( | |
'search_results_template', | |
[ | |
'section' => 'settings', | |
'label' => __( 'Search Results Post Type' ), | |
'type' => \Elementor\Controls_Manager::SELECT, | |
'options' => influex_elm_cnd_get_post_types(), | |
] | |
); | |
} | |
} | |
$conditions_manager->get_condition( 'search' )->register_sub_condition( new Page_Template_Condition() ); | |
}, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment