- table of contents
# Download WordPress core
$ wp core download --locale=ja --version=6.0.3 --force
# Drop WordPress DB
$ wp db drop --yes
# Create DB & Install WordPress
$ wp db create && wp core install --url=https://192.168.56.10:4055 --title=Example --admin_user=yugo --admin_password=yugo [email protected]
# Import db.sql & Replace domain in DB
$ siteurl=`wp option get siteurl` && home=`wp option get home` && echo $siteurl && echo $home && wp db drop --yes && wp db create && wp db query < ./_db/db.sql && wp search-replace `wp option get siteurl` $siteurl && wp search-replace `wp option get home` $home
https://gist.github.com/regepan/6d9767fd56339d4bdfe501aad14cfde3
https://github.com/woocommerce/theme-customisations
- https://wordpress.org/plugins/duplicate-post/
- https://wordpress.org/plugins/wp-multibyte-patch/
- https://wordpress.org/plugins/wp-mail-catcher/
- https://ja.wordpress.org/plugins/siteguard/
Install, But no need activate in test/local server. - https://wordpress.org/plugins/add-featured-image-column/
For Japanese bug fix.
https://developer.wordpress.org/reference/functions/get_attached_file/
https://codex.wordpress.org/Conditional_Tags
// can use array
is_page( array( 'page-name-a', 'page-name-b', 'page-name-c' ) )
is_singular( 'products' )
https://wordpress.org/plugins/wordpress-popular-posts/
/**
* Retrieves popular posts IDs.
* https://wordpress.org/support/topic/get-popular-post-id-as-an-array-with-no-html/
*
* @param string $range
* @param int $limit
* @param string $post_type
*
* @return array
*/
function get_popular_posts_ids( $range = 'last7days', $limit = 10, $post_type = 'post' ) {
$post_IDs = array();
$query = new \WordPressPopularPosts\Query( [
'post_type' => $post_type,
'range' => $range,
'limit' => $limit,
] );
$popular_posts = $query->get_posts();
// Popular posts found, get their IDs
if ( is_array( $popular_posts ) && ! empty( $popular_posts ) ) {
foreach ( $popular_posts as $popular_post ) {
$post_IDs[] = $popular_post->id;
}
}
return $post_IDs;
}
global $post;
$post_ids = get_popular_posts_ids( 'last30days', 5 );
$posts = get_posts( array(
'posts_per_page' => 5,
'post_type' => 'post',
'include' => $post_ids,
'orderby' => 'post__in',
) );
foreach ( $posts as $post ) {
setup_postdata( $post );
the_time( 'Y.m.d' );
the_title();
}
wp_reset_postdata();
https://haniwaman.com/wordpress-ajax/
define( 'WP_DEBUG', false );
http://hookr.io/filters/comment_notification_text/
Pass values from PHP to JS.
https://developer.wordpress.org/reference/functions/wp_localize_script/
function set_query_vars( $qvars ) {
$qvars[] = 'xxx';
return $qvars;
}
add_filter( 'query_vars', 'set_query_vars' );
# include template
get_template_part( 'inc/parts', 'xxx' );
# image path
<img src="<?= esc_url( get_template_directory_uri() ); ?>/img/common/header/logo.png" alt="">
# /var/www/html/example/wp-content/themes/twentyten
get_template_directory()
-
"repeater" feature needs to buy "repeater" plugin.
https://www.advancedcustomfields.com/ -
Query posts by custom fields(search ACF plugin data).
Need to use "LIKE" search for checkbox "serialized" data.
https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ -
Can get form field(input text, checkbox, etc...) from front side that is created on Admin.
https://www.advancedcustomfields.com/resources/get_field_object/
https://github.com/hijiriworld/intuitive-custom-post-order
https://wordpress.org/plugins/breadcrumb-navxt/
https://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/#Using
bcn_display() and bcn_display_list()
<div class="breadcrumb" typeof="BreadcrumbList" vocab="https://schema.org/">
<?php bcn_display(); ?>
</div>
- Duplicate Post https://ja.wordpress.org/plugins/duplicate-post/
- TinyMCE Advanced (remove auto p,br behavior)
- Regenerate Thumbnails https://ja.wordpress.org/plugins/regenerate-thumbnails/
- Custom Post Type UI https://ja.wordpress.org/plugins/custom-post-type-ui/
- https://eastcoder.com/code/wp-multibyte-patch/
e.g.) Contact Form 7 plugin sometimes does not work, because of Japanese. - Classic Editor https://wordpress.org/plugins/classic-editor/
- very simple
- many features
- background + static front text. Slide only background image.
do_shortcode('[jQueryArchiveList]');
if ( get_post_type() === 'product' ) {
// 'PRODUCT';
} else {
// 'NEWS';
}
global $wp_query;
$postType = $wp_query->query['post_type'];
get_post_type_archive_link( get_post_type() );
get_post_type_archive_link( 'product' );
- Try to remove SSL redirect plugins. Redirect loop might be the reason for something error.
- Try to access except TOP page.
- Start mailcatcher
- If Japanese is used in radio button, it is needed to install https://eastcoder.com/code/wp-multibyte-patch/ , then set Japanese language for WordPress whole site language.
- "email" input field is needed input required.
- If it is needed, Enable rest api on .htaccess
# Enable rest api
SetEnvIf Request_URI ".*" AllowRestApi
- If xserver is trial period, Contact form 7 not working.
[contact-form-7 id="1234" title="Contact form 1" html_id="contact-form-1234" html_class="form-container"]
[response]
add_filter( 'wpcf7_autop_or_not', '__return_false' );
https://qiita.com/matsumoto_sp/items/8613fc4a759f8a62da65
https://ja.wordpress.org/plugins/contact-form-7-multi-step-module/
https://firegoby.jp/archives/5309
https://www.youfit.co.jp/archives/1485
ini_set('error_reporting', E_ALL | ~E_STRICT);
# <? ?> is allowed
php_flag short_open_tag On
/**
* Template Name: Name
*/
<a href="<?= esc_url( home_url( 'xxx/' ) ); ?>">
<?php
if ( date( 'U' ) - get_the_time( 'U', $post->ID ) < 24 * 60 * 60 * 30 ) {
?>
<span class="label label-red">NEW</span>
<?php
}
?>
https://developer.wordpress.org/themes/basics/template-hierarchy/
https://developer.wordpress.org/files/2014/10/wp-hierarchy.png
while ( have_posts() ) {
the_post();
the_title();
the_content();
}
https://codex.wordpress.org/Template_Tags/get_posts#Access_all_post_data
<?php
global $post;
$last_posts = get_posts( array(
'posts_per_page' => 3,
'post_type' => 'news',
) );
foreach ( $last_posts as $post ) {
setup_postdata( $post );
?>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php
the_content();
}
wp_reset_postdata();
?>
https://developer.wordpress.org/reference/functions/wp_get_archives/
<?php
wp_get_archives( array(
'post_type' => 'post',
'type' => 'monthly',
'show_post_count' => true,
) );
?>
<ul>
<?php
wp_list_categories(array(
"title_li" => "",
));
?>
</ul>
the_category( ' ' );
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
CATEGORIES
</h3>
</div>
<div class="list-group">
<?php
$categories = get_categories();
foreach ( $categories as $category ) {
?>
<a href="<?= get_category_link( $category->term_id ); ?>" class="list-group-item <?= is_category( $category->name ) ? 'active' : ''; ?>">
<?= $category->name; ?>
<span class="badge">
<?= $category->category_count; ?>
</span>
</a>
<?php
}
?>
</div>
</div>
/*
*
---------------------------------------------------------*/
function my_excerpt_length( $length ) {
return 80;
}
add_filter( 'excerpt_length', 'my_excerpt_length' );
jQuery(function ($) {
$('.element').on('click', function() {
$(this).hide();
});
});
<?php the_widget( 'bizcalendarwidget' ); ?>
get_the_title( get_option('page_for_posts', true) );
post_type_archive_title();
// Category
$cat = get_the_category();
$catId = $cat[0]->cat_ID;
$catName = $cat[0]->name;
$catSlug = $cat[0]->category_nicename;
$link = get_category_link($catId);
// Custom post category(taxonomy)
$category = get_the_terms( $post->ID, 'product-category' );
$catName = $category[0]->name;
https://setting-tool.net/wordpress-p-br-auto-format
<?php
if ( get_the_post_thumbnail() ) {
?>
<p>
<?php
the_post_thumbnail( 'post-thumbnail', array(
'class' => 'img-fluid',
'alt' => get_the_title(),
) );
?>
</p>
<?php
}
?>
// title
mb_strimwidth( get_the_title(), 0, 60, "...", "UTF-8" );
// content
$content = wp_strip_all_tags( get_the_content() );
nl2br( mb_strimwidth( $content, 0, 100, "...", "UTF-8" ) );
<?php
get_header();// get header.php
get_footer();// get footer.php
wp_head();
wp_footer();
$post_type = get_query_var( 'post_type' );// if custom post type.
var_dump( $post_type );
<ul class="nav navbar-nav">
<li<?= (is_home()) ? ' class="active"' : ''; ?>>
<a href="<?= esc_url(home_url('/')); ?>">
TOP page
</a>
</li>
<li class="<?= ( is_home() or is_singular( 'post' ) or is_category() ) ? 'active' : ''; ?>">
<a href="<?= esc_url( home_url( 'news/' ) ) ?>">
News
</a>
</li>
<li class="<?= ( ( $post_type === 'products' ) or is_tax( 'product_category' ) ) ? 'active' : ''; ?>">
<a href="<?= esc_url(home_url('products/')); ?>">
do_shortcode( '[addtoany]' );
http://qiita.com/wonda/items/ee33ec26028e52cf9336
utf8mb4_unicode_520_ci
↓
utf8mb4_unicode_ci
require_once('../wp-blog-header.php');
http://qiita.com/OJI3T/items/f3cd1219cb722b0c7eb8
http://www.miraclesalad.com/webtools/md5.php
hoge
ea703e7aa1efda0064eaa507d9e8ab7e
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ https://interconnectit.com/blog/2009/10/07/migrating-a-wordpresswpmubuddypress-website/
https://nskw-style.com/2014/wordpress/wordpress-app-with-rewrite-api.html
After restore backup from Mac Time machine, MySQL show above error. https://cortyuming.hateblo.jp/entry/20120412/p1
https://codex.wordpress.org/Plugin_API/Action_Reference
https://wordpress.org/plugins/wp-multibyte-patch/
$ wp plugin install wp-multibyte-patch --activate
<body <?php body_class(); ?>>
https://developer.wordpress.org/reference/functions/wp_robots_no_robots/
add_filter( 'wp_robots', 'wp_robots_no_robots' );