致命错误:调用Resturant插件文件Restaurants.php中的非对象上的成员函数update()

时间:2013-08-13 作者:Malthesh

当我在wordpress中点击自定义帖子类型中的发布或保存按钮时,它会显示上述错误。我使用的是单一数据库(即gls),但该数据库共享两个站点的数据。问题是,每当我更新餐厅帖子时,单击“发布”或“保存草稿”按钮后,就会出现上述错误。请帮助我。。。这是我的密码

function save_restaurant()
{ 
    //start function save
    global $wpdb;
    global $gldb;
    global $post;

    $glpost=get_post($post->ID);

    if($post->post_type == \'page\') { return; }
    else if($post->post_type == \'post\') { return; }

    if($post->post_type == \'restaurant\')
        {   //start post type check


            $restaurant = $wpdb->get_row( "SELECT * FROM  `wp_restaurant` WHERE `post_id`=\'".$post->ID."\'" );
            if($restaurant->post_id==$post->ID)
            { // post is exist or not

                if($_POST[\'gl\']==1 && $restaurant->gl_postid!=0)
                { // chec for gl exit  page and gl id exit =1       !0 


                    $gldb->update(\'wp_posts\', array( 

                    //elements
                        ), 
                    array( \'ID\' => $restaurant->gl_postid ), 
                    array( 
                        //element
                        ), 
                    array( \'%d\' )
                    ); 

                    $wpdb->update(\'wp_restaurant\', array(


                    ), 
                    array( \'post_ID\' => $post->ID ), 
                    array( 
                        //elements
                    ), 
                    array( \'%d\' ) );
                }// end check for gl exit  page and gl id exit =1       !0 
                else if($_POST[\'gl\']==1 && $restaurant->gl_postid==0)
                {// check for gl exit  page and gl id exit =0       !0 

                    $gldb->insert(\'wp_posts\', array( 
                        //elements
                        ), 
                    array( 
                        //elements
                        )
                    ); 
                    $last = $gldb->get_row("SHOW TABLE STATUS LIKE \'wp_posts\'");
                    $glid  = $last->Auto_increment-1;
                    $wpdb->update(\'wp_restaurant\', array(
                        //elements
                    ), 
                    array( \'post_ID\' => $post->ID ), 
                    array( 
                        //elements
                        ) , 
                    array( \'%d\' )
                    );
                }// ending check for gl exit  page and gl id s
                else if($_POST[\'gl\']==0 && $restaurant->gl_postid!=0)
                {// check for gl exit  page and gl id exit =0       !0 

                    $gldb->update(\'wp_posts\', array( 
                        //elements
                        ), 
                    array( \'ID\' => $restaurant->gl_postid ), 
                    array( 
                        //elements
                        ), 
                    array( \'%d\' )
                    ); 

                    $wpdb->update(\'wp_restaurant\', array(
                        //elements
                    ), 
                    array( \'post_ID\' => $post->ID ), 
                    array( 
                        //elements
                    ), 
                    array( \'%d\' ) );
                }// ending check for gl exit  page and gl id exit =0        !0 
                else
                {// check for gl exit  page and gl id exit else case
                    $wpdb->update(\'wp_restaurant\', array(
                        //elements
                    ), 
                    array( \'post_ID\' => $post->ID ), 
                    array( 
                        //elements
                    ), 
                    array( \'%d\' ) );
                }// ending check for gl exit  page and gl id exit else case
            } // ending post exist or not
            else
            { // else case post exist

                if( $_POST[\'gl\']==1)
                { // check for gl==1
                    $gldb->insert(\'wp_posts\', array( 
                        //elements

                        ), 
                    array( 
                        //elements 
                        )
                    ); 
                $last = $gldb->get_row("SHOW TABLE STATUS LIKE \'wp_posts\'");
                $glid  = $last->Auto_increment-1;
                $wpdb->insert(\'wp_restaurant\', 
                    array(
                        //elements

                    ), 
                    array( 
                        //elements
                        )
                    ); 
                }// ending check for gl==1
                else
                { // checki gl else
                    $wpdb->insert(\'wp_restaurant\', 
                    array(
                        //elements
                    ), 
                    array( 
                        //elements
                        )
                    ); 
                }// checki gl else
            }// ending else for post exist
        }// ending else case post type check
}//ending function save

1 个回复
SO网友:Marin Bînzari

将$gldb连接放在$wpdb之后,如下所示:

$wpdb = new wpdb( \'gls_wp874\', \'8nS83Pu4cy\', \'gls_wp874\', \'localhost\' );
$gldb = new wpdb( \'gl_wpdb12\', \'n7dmSl8h4P\', \'gl_wpdb12\', \'localhost\' );
您无法使用尚未建立的连接。。。

结束

相关推荐

Displaying oEmbed errors?

有时,通过oEmbed嵌入项目是不可能的,例如,当YouTube视频已禁用嵌入时。The oEmbed service will return a 401 Unauthorized, 并且不会转换代码。有没有办法通知用户这一点?当前的工作流是非直观的(至少对我来说),我更喜欢在WordPress页面上,或者更好的是,在编辑器中显示一条消息,说明对象无法嵌入。