简体   繁体   中英

get_header() Function not working in wordpress plugin folder

I searched on why my get_header() function is not working in my plugin. All possible solutions say that the index.php file might be corrupt. But in my case it's working fine. My error is different from other errors solved on stackexchange concerning get_header() .

Please also help me on how to show my searchresult.php from plugin folder. If I add any wordpress function in it, it says undefined function . like get_header() , plugin folder etc.

My code:

<?php
get_header();

// Start the loop.
global $wpdb;
$srh = $_POST['s'];
//get_search_query();

if(!empty($srh)) {

    echo $srh;
    // Search title from table
    $sql = "SELECT * FROM wp_article WHERE title LIKE '$srh'";
    $result = $wpdb->get_results($sql) or die(mysql_error());

    if(count($result) > 0) {
        foreach($result as $results) {
            echo $results->title;
            echo $results->desc;
        }
    } else {

        echo "no ";
    }

} // submit end

?>

searchform.php

<style>
.search{
    border:0px solid #E5E5E5;
width: 100%;
height:90px;
padding:0px;    


}
.search ul li{
    list-style:none;
    padding:0px;
    display:inline-block !important;
    position:relative;
    float:none !important;
    text-align:left;

}
.widget input.search-field[type="search"] {
width:100%; 
}

</style>


<div class="search"><?php

/**
 * Template for displaying search forms in Twenty Sixteen
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
$url = plugins_url();  
get_header();
?>

<form role="search" method="get" class="search-form" action="<?php echo $url; ?>/magicsearch/searchm.php" >
    <label>
        <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label', 'twentysixteen' ); ?></span>
        <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search &hellip;', 'placeholder', 'twentysixteen' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'twentysixteen' ); ?>" />
    </label>
    <button type="submit" class="search-submit"><span class="screen-reader-text"><?php echo _x( 'Search', 'submit button', 'twentysixteen' ); ?></span></button>
</form>
</div>

**My Plugin Dashboard file ** plugin_index.php

<?php
/*
Plugin Name: Magic Search
Plugin URI: #
Description: Magic Search use for to find article from archive otherwise query saved.
Author: Manmohan
Author URI: #
*/
// PLUGIN ACTIVATION BY CODE
//function myplugin_activate() {
    // Activation code here...
//}
//register_activation_hook( __FILE__, 'myplugin_activate' );
function createTable(){

    global $wpdb;
    $query = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix ."newkeyword (
        query_id INT NOT NULL AUTO_INCREMENT,
        keyword VARCHAR(25) NOT NULL,
        PRIMARY KEY (query_id)
        ) ENGINE=MyISAM  DEFAULT CHARSET=utf8";
    $wpdb->query($query);
}

register_activation_hook(__FILE__, 'createTable');

//ADD SHORTCODE 
register_activation_hook(__FILE__, 'searchbar_function');
add_shortcode('searchbar', 'searchbar_function');

function searchbar_function(){

    include('searchf.php'); 
    include('searchm.php'); 

}
// Hook for adding admin menus
add_action('admin_menu', 'disp_queries');
// action function for above hook
function disp_queries(){
    /*               Browser Top   Title use at                                                                                */
    /*               Title Text    WP Admin LFT Bar                                                                               */
    /*                  \/              \/                                                                            */

    add_menu_page( 'Magic Search', 'Magic Search', 'manage_options', 'searchpage', 'my_custom_menu_page', plugins_url( 'magicsearch/se.png' ), 6 ); 
}

function my_custom_menu_page(){
    include('adminresult.php'); 


//tguy_sm_summary_table(30);
    }







?>

have you set up the header and footer .php files in the theme folder? may seem like a silly question, but its been known to happen.

regarding the search question, im not 100% sure on that one, but this get_search_form topic may help

Is this a custom theme or one you have picked as default?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM