Skip to content

Instantly share code, notes, and snippets.

@platoosom
platoosom / gist:8043b4c70f2434911f647ad3ea7a68ca
Created Apr 30, 2020
Wordpress query not include current post
View gist:8043b4c70f2434911f647ad3ea7a68ca
$termlists = array();
$terms = get_the_terms( get_the_ID(), 'podcast-tag' );
if ( $terms && is_array( $terms ) ) {
foreach ( $terms as $term ) {
$termlists[] = $term->slug;
}
}
$query_args = array(
@platoosom
platoosom / gist:7f80093e58523b11028695396073a720
Created Apr 30, 2020
Wordpress get custom post by custom tags.
View gist:7f80093e58523b11028695396073a720
$terms = get_the_terms( get_the_ID(), 'podcast-tag' );
if ( $terms && is_array( $terms ) ) {
foreach ( $terms as $term ) {
$termlists[] = $term->slug;
}
}
$query_args = array(
'post_type' => 'podcast',
View gist:22337e15977639beca0ed981687d3f4c
<?php
/**
* Register and load the widget
*/
add_action( 'widgets_init', 'topgear_load_widgets' );
function topgear_load_widgets() {
register_widget( 'Dream_Car_Calculator_Widget' );
}
@platoosom
platoosom / gist:71008f635392fd7281581ad852fedf0f
Last active Apr 17, 2020
Wordpress insert data into custom database
View gist:71008f635392fd7281581ad852fedf0f
/**
* Insert LinkUrl to wp_imported_articles table
*
* @param $LinkUrl
* @return int
*/
function topgear_save_LinkUrl_todatabase($LinkUrl)
{
global $wpdb;
@platoosom
platoosom / gist:a7c2544a4930c4a06ba384e4c76936df
Created Apr 17, 2020
wordpress query data from custom table
View gist:a7c2544a4930c4a06ba384e4c76936df
/**
* Check post by postmeta
* @param $LinkUrl
* @return int
*/
function topgear_post_exists_by_LinkUrl($LinkUrl)
{
global $wpdb;
$wpdb->get_results("SELECT ID FROM `{$wpdb->base_prefix}imported_articles` WHERE LinkUrl = '".$LinkUrl."' ");
@platoosom
platoosom / gist:2d5c4f1d7aedf5f08ab05c1a70f84a41
Created Apr 17, 2020
Wordpress สร้างฐานข้อมูลขึ้นมาใหม่ถ้าหากมันไม่มี
View gist:2d5c4f1d7aedf5f08ab05c1a70f84a41
/**
* Create custom table to keep import article url
*/
add_action('init', 'topgear_create_import_exists_table');
function topgear_create_import_exists_table()
{
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
@platoosom
platoosom / gist:b9913a8ff8ca00bb93726ab435a05b7f
Created Apr 17, 2020
wpml insert post in english language ให้โฟกัสที่บรรทัด 105-117 มันใช้ hook wpml_set_element_language_details ในการยัดภาษาเข้าไป ถ้าไม่มี hook นี้เวลาสร้างโพสต์มันจะเซฟเป็นภาษา default
View gist:b9913a8ff8ca00bb93726ab435a05b7f
function topgear_midnight_cron_task()
{
$action = isset($_GET['action'])? $_GET['action']: null;
if($action !== 'cron'){ return ;}
// Find Author
$user = get_user_by( 'login', 'Topgear' );
$userID = ($user->ID)? $user->ID : 4;
// Find Category
@platoosom
platoosom / gist:742e7fff640b36a68a2ee6f9f7a01975
Created Apr 17, 2020
wordpress check plugin activated เช็กว่าปลักอินเป้าหมาย activated หรือไม่
View gist:742e7fff640b36a68a2ee6f9f7a01975
if ( is_plugin_active('sitepress-multilingual-cms/sitepress.php') ) {
include_once( WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php' );
$_POST['icl_post_language'] = $language_code = 'en'; // change the language code
wpml_add_translatable_content( 'post_my_post_type', $ID, $language_code );
}
@platoosom
platoosom / gist:36bec5ece165317b6b3d55663b344148
Created Apr 16, 2020
Wordpress insert new post with thumbnail เวิร์ดเพรส ดึงรายการโพสต์มาจาก json จากนั้นสร้างโพสต์ใหม่และใส่ thumbnail เข้าไปด้วย โค้ดนี้ไว้ลอกการดูดภาพมาทำ thumbnail และการสร้างโพสต์ด้วยโค้ด
View gist:36bec5ece165317b6b3d55663b344148
$action = isset($_GET['action'])? $_GET['action']: null;
if($action !== 'cron'){ return ;}
// Find Author
$user = get_user_by( 'login', 'Topgear' );
$userID = ($user->ID)? $user->ID : 4;
// Find Category
$category = get_category_by_slug( 'car-news' );
$categoryID = ($category->term_id)? $category->term_id: null;
View gist:483d318410bc57b227dc11d9f9c589c1
<div class="container mt-100">
<h1 class="title text-center mb-40">Featured Guests</h1>
<div class="row">
<div class="col-sm-4 col-6">
<div class="item-advisory">
<?php
$args = array(
'role' => 'featured_guest',
'orderby' => 'user_nicename',
'order' => 'ASC'
You can’t perform that action at this time.