timthumb

functions.php

/* ===============================================
# timthumb
=============================================== */

define('THEME_DIR', get_template_directory_uri());
/* Timthumb CropCropimg */
function thumbCrop($img='', $w=false, $h=false , $zc=1, $a=false, $cc=false ){
    if($h)
        $h = "&h=$h";
    else
        $h = "";

    if($w)
        $w = "&w=$w";
    else
        $w = "";
	if($a)
        $a = "&a=$a";
    else
        $a = "";
	if($cc)
        $cc = "&cc=$cc";
    else
        $cc = "";

    $img = str_replace(get_bloginfo('url'), '', $img);
     $image_url = str_replace("http://","http://",THEME_DIR) . "/timthumb/timthumb.php?src=" . $img . $h . $w. "&zc=".$zc .$a .$cc;
    return $image_url;

}

HTML

<?php
						if (has_post_thumbnail()) {
							$image_url1 = get_the_post_thumbnail_url( get_the_ID(),'large');
							$image_url2 = get_template_directory_uri() . '/timthumb/timthumb.php?src=' . $image_url1 .'&amp;h=400' . '&amp;w=660';
							?>
							<img src="<?php echo $image_url2; ?>">
						<?php } else { ?>
							<img src="https://placehold.jp/eeeeee/ffffff/660x400.png?text=No%20photo" alt="">
						<?php
						}
						?>

[WordPress]コンテンツエディタ削除

/* ===============================================
# エディタ削除
=============================================== */

function top_disable_block_editor($use_block_editor, $post){
	$post_type = $post->post_type;
	$post_name = $post->post_name;

	if($post_type === 'post' || $post_type === 'directsalon') return false;
	return $use_block_editor;
}
add_filter( 'use_block_editor_for_post', 'top_disable_block_editor', 10, 2 );

WordPress データベースからユーザーアカウントを作成する方法

1. wp_usersテーブルへの追加

・user_login:ユーザーID
・user_pass:md5を選択し、md5変換したパスワードを入力
・user_email:受信できるメールアドレス
・user_registered:(任意の日付)
・user_status:0

MD5変換ツールはこちら

2. wp_usermetaテーブルへ権限情報追加

・user_id…先ほど追加したユーザーIDの数値
・meta_key…「wp_capabilities」と入力
・meta_value…「a:1:{s:13:”administrator”;b:1;}」と入力

・user_id…先ほど追加したユーザーIDの数値(上と同じもの)
・meta_key…「wp_user_level」と入力
・meta_value…「10」と入力

WordPress カレント表示

<?php
  $current_page_id = $wp_query->get_queried_object_id();
  $args = array(
      'posts_per_page' => -1,
      'post_type' => 'カスタム投稿'
  );
  $my_posts = get_posts($args);
?>
<?php foreach ($my_posts as $post): setup_postdata($post); ?>
  <li class="<?php if ($current_page_id == $post->ID ) {echo 'is_active';} ?>">
      <a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
      </a>
  </li>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>

WordPressの個別ページに投稿一覧を表示してページャーがうまく動かない場合

$paged = get_query_var('page') ? get_query_var('page') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 12,
'paged' => $paged,
);
$my_query = new WP_Query($args);
$max_num_pages = $my_query->max_num_pages;
if( $my_query -> have_posts() ) :
while($my_query -> have_posts()) : $my_query -> the_post();
endwhile;
endif;

if (function_exists('responsive_pagination')) {
responsive_pagination($additional_loop->max_num_pages);
}

wp_reset_postdata();

$paged = get_query_var(‘page’) ? get_query_var(‘page’) : 1;がポイント。
$paged = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1;ではない。

WordPressの検索結果にカスタムフィールドの値を追加する

function cf_search_join( $join ) {
	global $wpdb;
	if ( is_search() ) {
		$join .= ' LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
	}
	return $join;
}
add_filter( 'posts_join', 'cf_search_join' );

function cf_search_where( $where ) {
	global $wpdb;
	if ( is_search() ) {
		$where = preg_replace(
			"/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
			"(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)", $where );

		// 特定のカスタムフィールドを検索対象から外す(※1)
//		$where .= " AND (" . $wpdb->postmeta . ".meta_key NOT LIKE 'number')";
//		$where .= " AND (" . $wpdb->postmeta . ".meta_key NOT LIKE 'zip')";
//		$where .= " AND (" . $wpdb->postmeta . ".meta_key NOT LIKE 'access')";
	}
	return $where;
}
add_filter( 'posts_where', 'cf_search_where' );

function cf_search_distinct( $where ) {
	global $wpdb;
	if ( is_search() ) {
		return "DISTINCT";
	}
	return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );

// 検索対象を『タイトルのみ』にする
function __search_by_title_only( $search, & $wp_query ) {
	global $wpdb;
	if ( empty( $search ) )
		return $search; // skip processing - no search term in query
	$q = $wp_query->query_vars;
	$n = !empty( $q[ 'exact' ] ) ? '' : '%';
	$search =
		$searchand = '';
	foreach ( ( array )$q[ 'search_terms' ] as $term ) {
		$term = esc_sql( like_escape( $term ) );
		$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
		$searchand = ' AND ';
	}
	if ( !empty( $search ) ) {
		$search = " AND ({$search}) ";
		if ( !is_user_logged_in() )
			$search .= " AND ($wpdb->posts.post_password = '') ";
	}
	return $search;
}
//add_filter( 'posts_search', '__search_by_title_only', 500, 2 );// (※2)

下記サイトを参考にしました。
WordPress内の検索対象にカスタムフィールドも適用する

現在のページにクラスを付与する

<nav>
    <ul>
        <li><a <?php if( is_page('concept') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>concept/">コンセプト</a></li>
        <li><a <?php if( is_page('news') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>news/">新着情報</a></li>
        <li><a <?php if( is_page('menu') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>menu/">メニュー_</a></li>
        <li><a <?php if( is_page('staff') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>staff/">スタッフ</a></li>
        <li><a <?php if( is_page('salon') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>salon/">サロン案内</a></li>
        <li><a <?php if( is_page('contact') ) { echo 'class="current"'; } ?> href="<?php echo esc_url( home_url( "/" ) ); ?>contact/">お問い合わせ</a></li>
    </ul>
</nav>