Support » Plugin: PIKLIST - Easily Build Fields, Forms, Settings, Widgets and More. » Adding Piklist Support to plugin causes fatal error

  • Kamal Ahmed


    Thank you for making this awesome plugin. However, I am very sad that I am facing problem with it. I have a function to query database to find all elementor templates and I used it in redux config file for displaying a settings with elementor template lists. It is a normal query. Everything works fine if I do not activate piklist. When I activate piklist and add support in my plugin for piklist then I get the following error:

    [07-Mar-2019 07:52:40 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get() on null in /Applications/MAMP/htdocs/themexdev/wp-includes/query.php:28
    Stack trace:
    #0 /Applications/MAMP/htdocs/themexdev/wp-content/plugins/piklist/includes/class-piklist-wordpress.php(610): get_query_var('taxonomy_relati...')
    #1 /Applications/MAMP/htdocs/themexdev/wp-includes/class-wp-hook.php(288): Piklist_WordPress::relation_taxonomy(' AND ( \n  ( wp_...')
    #2 /Applications/MAMP/htdocs/themexdev/wp-includes/plugin.php(251): WP_Hook->apply_filters(' AND ( \n  ( wp_...', Array)
    #3 /Applications/MAMP/htdocs/themexdev/wp-includes/class-wp-query.php(2519): apply_filters_ref_array('posts_where', Array)
    #4 /Applications/MAMP/htdocs/themexdev/wp-includes/class-wp-query.php(3387): WP_Query->get_posts()
    #5 /Applications/MAMP/htdocs/themexdev/wp-includes/class-wp-query.php(3496): WP_Query->query(Array)
    #6 /Applications/MAMP/htdocs/themexdev/wp-content/plugins/xlaw-core/includes/xlaw-core-helper.php(15): WP_Query->__construct(Array)
    #7 /Applications/MAMP/htdocs/themexd in /Applications/MAMP/htdocs/themexdev/wp-includes/query.php on line 28

    then I did some debugging, and I found some idea of the reason why it happens. If I call the function in the init hook then no error is generated. So, it means, your plugin-piklist, might have load my plugin and its file too early before WP_Query and other wp core functions are ready.

    So, can you please tell me at which hook/time piklist load my plugin or how I can avoid such situation of getting error when using the WP_Query class.

    Thanks a lot.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Kamal Ahmed


    Here is the function, calling to this when piklist active generates fatal error, otherwise, it works fine.

    	 * It fetches all saved elementor templates and return it in an array
    	 * @return array
    	function xlaw_get_elementor_tmpl_lists() {
    		if ( ! did_action( 'elementor/loaded' ) ) {
    			return [''=> 'Elementor has been not loaded'];
    		//calling this function before init hook will generate fatal error
    		$templates_query = new WP_Query(
    				'post_type' => 'elementor_library',
    				'post_status' => 'publish',
    				'posts_per_page' => -1,
    				'orderby' => 'title',
    				'order' => 'ASC',
    				'meta_query' => [
    						'key' => '_elementor_template_type',
    						'value' => ['page', 'single'], // we can also use section, widget, header, footer etc.
    		$templates = [];
    		if ( $templates_query->have_posts() ) {
    			$templates = [ '0' => __( 'Default Template', 'xlaw-core' ) ];
    			foreach ( $templates_query->get_posts() as $p ) {
    				/** @var WP_Post $p*/
    				$templates[$p->ID] = $p->post_title;
    		return $templates;
    Plugin Author Steve Bruner


    I believe there is a patch proposed on Github. Can you check if that works:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding Piklist Support to plugin causes fatal error’ is closed to new replies.