Showing posts with label wpdb. Show all posts
Showing posts with label wpdb. Show all posts

Sunday, 26 October 2025

Cara-Cara Untuk Bypass/Solve: Database Problem.

 Warning: Attempt to read property "post_status" on null in /home/xxx/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/xxxx/public_html/wp-admin/includes/template.php on line 2302 Warning: Attempt to read property "post_status" on null in /home/xxx/public_html/wp-admin/includes/template.php on line 2308 Warning: Attempt to read property "post_status" on null in /home/xxxpublic_html/wp-admin/includes/template.php on line 2312 Warning: Attempt to read property "ID" on null in /home/xxxx/public_html/wp-admin/includes/template.php on line 2316

Cara-Cara Untuk Bypass/Solve:

1. Quick Fix - Hide Warning (Sementara)

Tambahkan dalam wp-config.php:

php
// Sembunyikan warning (temporary solution)
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
// ATAU
ini_set('display_errors','Off');

2. Fix Root Cause - Database Repair

Error ini biasanya disebabkan corrupted post data dalam database.

Langkah-langkah:

  1. Enable Database Repair:

php
// Dalam wp-config.php
define('WP_ALLOW_REPAIR', true);
  1. Pergi ke URLyourwebsite.com/wp-admin/maint/repair.php

  2. Klik kedua-dua butang:

    • "Repair Database"

    • "Optimize Database"

3. Plugin Solution

Install plugin "Health Check & Troubleshooting":

  • Pergi ke Plugins → Add New

  • Cari "Health Check"

  • Activate dan run troubleshooting mode

4. Manual SQL Fix (Advanced)

Jalankan query ini dalam phpMyAdmin:

sql
-- Cari posts yang corrupted
SELECT * FROM wp_posts WHERE post_status IS NULL OR post_title IS NULL;

-- Delete posts yang corrupted (HATI-HATI!)
DELETE FROM wp_posts WHERE post_status IS NULL;

5. Disable Problematic Plugin/Theme

php
// Dalam wp-config.php - disable plugins
define('WP_DISABLE_FATAL_ERROR_HANDLER', true);

// ATAU rename folder plugins via cPanel/FTP
// wp-content/plugins → wp-content/plugins-deactivate

6. Custom Code Fix (Permanent)

Tambahkan dalam functions.php theme anda:

php
// Fix untuk null post object
add_action('wp_loaded', 'fix_null_post_errors');
function fix_null_post_errors() {
    if (is_admin() && !defined('DOING_AJAX')) {
        // Clear corrupted post cache
        wp_cache_flush();
    }
}

Recommen

Sunday, 6 September 2020

Wordpress Dashboard Widget. Multiple

 $helloMuhaza = 'Hello, Muhaza Nak Letak Something Sini'.' <a href="/">a</a>';


add_action( 'wp_dashboard_setup', 'muhaza_widget_001' );

function muhaza_widget_001() {

    wp_add_dashboard_widget(

        'muhaza_001_dashboard_widget',/*nama widget*/

        'Widget Muhaza 001',/*Screen Option Button*/

        'muhaza_widget_001_display'/*function*/

    );

}


function muhaza_widget_001_display() {

    echo $GLOBALS['helloMuhaza'];

}


//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

add_action( 'wp_dashboard_setup', 'muhaza_widget_002' );

function muhaza_widget_002() {

    wp_add_dashboard_widget(

        'muhaza_002_dashboard_widget',/*nama widget*/

        'Widget Muhaza 002',/*Screen Option Button*/

        'muhaza_widget_002_display'/*function dalam*/

    );

}


function muhaza_widget_002_display() {

    echo $GLOBALS['helloMuhaza'];

}


Monday, 31 August 2020

Add data into wpdb Column when user login

//how to update current user role in custom user column inside wpdb.
//update must effect only the current user

global $wpdb;
$user_Tag = $current_user->ID; //ID hook
$push_status = 'customer'; // custom string

if(current_user_can('customer') ) {$wpdb->update( 'wpdb_table_name', array( 'wpdb_role_column' =>$push_status), array( 'wpdb_id_column' => $user_Tag ), array( '%s' ));
}

Thursday, 27 August 2020

wpdb List

//absolute path to wp-load.php, or relative to this script
//e.g., ../wp-core/wp-load.php
include( 'trunk/wp-load.php' );
//grab the WPDB database object, using WP's database
//more info: http://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
//make a new DB object using a different database
//$mydb = new wpdb('username','password','database','localhost');
//basic functionality
//run any query
$wpdb->query( "SELECT * FROM wp_posts" );
//run a query and get the results as an associative array
$wpdb->get_results( "SELECT * FROM wp_posts" );
//get a single variable
$wpdb->get_var( "SELECT post_title FROM wp_posts WHERE ID = 1" );
//get a row as an assoc. array
$wpdb->get_row( "SELECT * FROM wp_posts WHERE ID = 1" );
//get an entire column
$wpdb->get_col( "SELECT post_title FROM wp_posts" );
//insert data into a table… sql protection?
$wpdb->insert( 'wp_posts', array( 'post_title' => 'test', 'ID' => 5 ), array( '%s', '%d') );
//update an existing row
$wpdb->update( 'wp_posts', array( 'post_title' => 'test2'), array( 'ID' => 5 ), array( '%s' ) );
//escaping queries
$wpdb->query( $wpdb->prepare( "UPDATE INTO wp_posts set post_title = %s WHERE ID = %d", 'test2', 5 ) );
//two steps to insert a post…
//define the post… all field optional
$post = array(
'post_title' => 'test',
'post_type' => 'station',
'post_status' => 'publish',
'post_author' => 'greg',
);
//insert
$id = wp_insert_post( $post );
//store key/value pair
update_post_meta( $id, 'expiration', '201101010' );
//retrieve key/value pair
$meta = get_post_meta( $id, 'expiration', true );
//search for posts by key/value pair
$posts = get_posts( 'expiration=20110110' );
//associate taxonomy terms with a post
wp_set_post_terms( $id, array( 'red', 'blue', 'green'), 'colors' );
//query posts by taxonomy term
$posts = get_posts( 'color=red' );
//wizards for creating taxonomy / post types
//will output a plugin that you just drop into /wp-content/plugins and activate
//http://themergency.com/generators/wordpress-custom-taxonomy/
//http://themergency.com/generators/wordpress-custom-post-types/
//Cache
//store a value in cache
wp_cache_set( 'unique_key', $data );
//retrieve value from cache
$data = wp_cache_get( 'unqiue_key' );
/* additional things to do
1) Install W3 Total Cache to get DB and object caching
2) Use the front end / admin UI to browse / sort data
*/

Tembus Gmail dengan TXT record

Type: TXT Name: @ / domainname.com Loadtime : 14400 Value: v=spf1 a mx ip4:SERVER_IP include:netkl.org ~all