Skip to content

Instantly share code, notes, and snippets.

@konweb
konweb / function.php
Last active May 28, 2020 07:40
To have a hierarchy to post
<?php
/**
* To have a hierarchy to the default post
*/
function action_register_post_type_args( $args, $post_type ) {
if ( $post_type == 'post' ) {
$args['hierarchical'] = true;
$args['supports'] = array_merge( $args['supports'], array('page-attributes') );
}
return $args;
@konweb
konweb / functions.php
Created April 9, 2020 00:57
At login redirect processing
/**
* At login redirect processing
* @param string $user_login
* @param array $user
*/
function action_wp_login($user_login, $user) {
if ( 'administrator' !== $user->roles[0] ) {
wp_safe_redirect( home_url(), 301 );
exit();
}
<?php
$paged = $paged ?: 1;
$view_num = 10;
$the_query = new WP_Query([
'post_type' => 'blog',
'posts_per_page' => $view_num,
'paged' => $paged,
]);
$max_count = $the_query->found_posts;
@konweb
konweb / add-auto_increment
Created February 21, 2020 08:20
Add AUTO_INCREMENT
ALTER TABLE `wp_commentmeta` CHANGE `meta_id` `meta_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_comments` CHANGE `comment_ID` `comment_ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_links` CHANGE `link_id` `link_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_options` CHANGE `option_id` `option_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_postmeta` CHANGE `meta_id` `meta_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_termmeta` CHANGE `meta_id` `meta_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_terms` CHANGE `term_id` `term_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `wp_term_taxonomy` CHANGE `term_taxonomy_id` `term_taxonomy_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
@konweb
konweb / front-page.php
Last active February 13, 2020 08:53
multisite get all post
<?php
global $wpdb;
$post_type = 'post'
$paged = get_query_var('paged') ?: 1;
$posts_per_page = 5;
$start = $posts_per_page * ($paged - 1);
$sql = '';
$sites = get_sites();
foreach($sites as $key => $site){
@konweb
konweb / app.js
Last active October 3, 2019 05:49
JS Clipborad Copy
document.addEventListener("DOMContentLoaded", (ev) => {
const copyEl = document.querySelector('#copy')
copyEl.addEventListener("click", (ev) => {
ev.preventDefault()
const input = document.createElement('input')
input.readOnly = true
input.value = location.href
@konweb
konweb / index.php
Last active September 26, 2019 02:59
post thumbnail migration code
<?php
$the_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 20,
'offset' => 0,
) );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
if (get_the_post_thumbnail_url(get_the_ID(), 'full')) continue;
@konweb
konweb / functions.php
Created June 12, 2019 13:47
Filter function to change template file
<?php
function custom_template_include( $template ) {
if ( is_single() && in_category( 'news' ) ) {
$new_template = locate_template( array( 'single-news.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
@konweb
konweb / memo.md
Created May 28, 2019 04:58
nginx Command memo

Start

CentOS7

systemctl start nginx

Before CentOS6

service start nginx
@konweb
konweb / function.php
Last active May 14, 2019 07:00
Change template file to be Include
<?php
/**
* Change template file to be Include
*/
function mytheme_template_include( $template ) {
global $post;
$recruit_post = get_page_by_path('recruit');
if ( $post->post_parent === $recruit_post->ID ) {