都道府県 / 州 / 郡 woocommerce

翻訳ファイルの修正

WooCommerceの日本語ファイル
/wp-content/languages/plugins/woocommerce-ja.mo

woocommerce-ja.po が編集用のファイルなので、このファイルをダウンロード

翻訳ファイルの編集ソフト「Poedit」 をインストール
書き換え後に ファイル MOにコンパイル → woocommerce-ja.mo をアップして上書き

WP_Query から投稿記事やらアイキャッチやらタグを取得


$the_query = new WP_Query($args);
  foreach($the_query->posts as $key=>$value){
    var_dump($value->ID, $value->post_date, $value->post_content);

   $thumb_id = get_post_thumbnail_id($postID);      // 指定した投稿のアイキャッチ画像の画像IDを取得
	$thumb_img = wp_get_attachment_image_src($thumb_id );
	$src = $thumb_img[0]; 


	$postID = get_the_ID();
			$fivesdrafts = $wpdb->get_results( 
				"SELECT name , slug
				FROM $wpdb->term_relationships
				LEFT JOIN $wpdb->term_taxonomy  USING (term_taxonomy_id)
				LEFT JOIN $wpdb->terms USING(term_id)
				WHERE object_id = $postID
				AND taxonomy = 'post_tag'"
			);
			 foreach ($fivesdrafts as $key => $val) {
				 $tag .= $val->slug . $val->name ; // スラッグ。タグ
			 }

固定ページ 特定のスラッグを親に持つ記事の表示 wordpress



/*
	固定ページ 特定のスラッグを親に持つ記事の表示
*/
	if ( $post->ancestors ) {
		foreach ( $post->ancestors as $post_anc_id ) {
			$post_id = $post_anc_id;
		} // foreach($post->ancestors as $post_anc_id){
	} else {
		$post_id = $post->ID;
	} // if($post->ancestors){

	if ( $post_id ) {
		$children = wp_list_pages( 'title_li=&child_of=' . $post_id . '&echo=0' );
		if ( $children ) { ?>
			<aside class="widget widget_child_page widget_link_list">
			<nav class="localNav">
			<h1 class="subSection-title"><a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo get_the_title( $post_id ); ?></a></h1>
			<ul>
			<?php  echo $children; ?>
			</ul>
			</nav>
			</aside>
		<?php } // if ($children)
	} // if ($post_id)
?>

 

WP_Queryを使わないループで特定のカテゴリのみ表示してページャーもつける

Woocommerce の商品カテゴリ


/* データの表示指定 */
$type =15;  // カテゴリID 
$item_count = 6; //1ページに表示したいアイテム数 
$sp = empty($_GET['pg']) ? 1 : $_GET['pg'] ;

$field = "SELECT object_id , p.post_title ,post_content,post_date,post_excerpt,post_name,
p.post_type , p.post_status, m.stock_quantity , m.min_price, m.max_price ,meta_value" ;

$query = "
FROM `$wpdb->term_relationships` as t
left join $wpdb->posts as p on p.id = t.object_id 
left join `$wpdb->wc_product_meta_lookup` as m on m.product_id = t.object_id 
left join `$wpdb->postmeta` as e on e.post_id = t.object_id 
WHERE `term_taxonomy_id` = %d AND p.post_type = 'product' AND p.post_status = 'publish' 
AND e.meta_key = '_price' " ;

$sql = $field . $query ." LIMIT %d, $item_count;";

$results = $wpdb->get_results( $wpdb->prepare( $sql ,$type ,($sp-1)*$item_count) );
foreach($results as $row) var_dump($row);
[/highlight_php]


このページのページャー

[highlight_php] <?php /* 以下、ページャーの表示 */ $field = "SELECT count(*) "; $sql = $field . $query ; $product_count = $wpdb->get_var( $wpdb->prepare( $sql , $type) ); $product_page = ceil( $product_count/$item_count); //ページ数 ?> <nav class="undernav pagination"> <?php if( $sp > 1){ echo ''; } ?> Page of <?php for( $i=1 ; $i <= $product_page; $i++){ if( $i == $sp ){ echo '', $i,''; }else{ echo '',$i,''; } } if( $sp < $product_page){ echo ''; } ?>

返答が正しい JSON レスポンスではありません。

#: wp-includes/js/dist/api-fetch.js:705
msgid "The response is not a valid JSON response


CentOSなら

Apache設定ファイルでmode rewriteを有効にする

  <Directory "/var/www/html">
    Options Indexes FollowSymLinks
     AllowOverride All  ←これ
    Require all granted
 </Directory>

Apache再起動

.htaccess が作られていないので以下の操作で作らせる
管理画面 → 設定 → パーマリンク
◎ 基本 → 保存
◎カスタム [ category / posttitle]