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
*/

wpdb Wordpress Table - Update Column Value

 <?php

/*

Template Name: Update Column

*/

?>

<?php

global $wpdb;

$pokemon = $current_user->ID;

$status = 'capture';

$checkPokedex = true;


if ($checkPokedex = true){

  $wpdb->update( 'wp_semak', array( 'peranan' => $status), array( 'pemilik' => $pokemon ), array( '%s' ) );

echo 'Gotta Catch em All';

} else {

echo 'Full Party';

}

?>


ref: https://gist.github.com/benbalter/1607991

Wednesday, 19 August 2020

Add Custom Woo Commerce My-Account Tab Page


// ------------------

// 1. Register new endpoint to use for My Account page

// Note: Resave Permalinks or it will give 404 error

  

function muhaza_add_extra_tab_endpoint() {

    add_rewrite_endpoint( 'extra-tab', EP_ROOT | EP_PAGES );

}

  

add_action( 'init', 'muhaza_add_extra_tab_endpoint' );

  

  

// ------------------

// 2. Add new query var

  

function muhaza_extra_tab_query_vars( $vars ) {

    $vars[] = 'extra-tab';

    return $vars;

}

  

add_filter( 'query_vars', 'muhaza_extra_tab_query_vars', 0 );

  

  

// ------------------

// 3. Insert the new endpoint into the My Account menu

  

function muhaza_add_extra_tab_link_my_account( $items ) {

    $items['extra-tab'] = 'Extra Tab';

    return $items;

}

  

add_filter( 'woocommerce_account_menu_items', 'muhaza_add_extra_tab_link_my_account' );

  

  

// ------------------

// 4. Add content to the new endpoint

  

function muhaza_extra_tab_content() {

echo '<h3>Premium WooCommerce Support</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>';

echo do_shortcode( ' /* your shortcode here */ ' );

}

  

add_action( 'woocommerce_account_extra-tab_endpoint', 'muhaza_extra_tab_content' );

// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format

CUSTOM FUNCTION FOR WORDPRESS LINK

 https://vegibit.com/the-top-100-most-commonly-used-wordpress-functions/

https://colorwhistle.com/wordpress-functions-list/

https://www.wpbeginner.com/wp-tutorials/25-extremely-useful-tricks-for-the-wordpress-functions-file/

Monday, 17 August 2020

CONNECT USING MYSQLI WITH EXAMPLE

 <?php

/* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "", "demo"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt select query execution $sql = "SELECT * FROM persons"; if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ echo "<table>"; echo "<tr>"; echo "<th>id</th>"; echo "<th>first_name</th>"; echo "<th>last_name</th>"; echo "<th>email</th>"; echo "</tr>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['last_name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "</tr>"; } echo "</table>"; // Free result set mysqli_free_result($result); } else{ echo "No records matching your query were found."; } } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?>


https://www.tutorialrepublic.com/php-tutorial/php-mysql-select-query.php

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...