タクソノミー ターム別 記事一覧  記事件数で全て見る

http://naoyu.net/wordpress/tax_query/583/
ここに感謝

そもそもタクソノミーのタームを全て取得するコードが
あまりメジャーじゃないから悩んだ。
これでカスタムポストの全記事をターム別に一覧表示できる。

【備考】
アーカイブページで表現できるのはポストタイプのみで
タクソノミーページの全記事アーカイブはタクソノミー – タクソノミー名では
そのテンプレートが使われなかった。
つまりそんな表示はできない
/タクソノミー名/ではぺーじがありません。
/タクソノミー名/ラベル名/で一覧が表示されたようにみえたが
タクソノミーphpで表示されただけで ラベル名の部分は適当なもじでも同じように全部でた。
つまりないからタクソノミーページを表示してるだけだ。

つまり
固定ページに書いて表現する。

デフォルトで この表現であったら良いのに。
そのうちなるかな?

タクソノミーのタームを全て取得するコード

$args = array(
'parent'       => 0,
'hierarchical' => 0,
'orderby'      => 'term_order', // Category Order and Taxonomy Terms Order を使用
'order'        => 'ASC'
);
    $taxonomy_name = 'cate_jirei';
    $taxonomys = get_terms($taxonomy_name,$args);
    if(!is_wp_error($taxonomys) && count($taxonomys)):
        foreach($taxonomys as $taxonomy_term):
        $url = get_term_link($taxonomy_term->slug, $taxonomy_name);
?>



<h3><div class="jirei_title"><i class="icon-doc-inv"></i>
<a href="<?php echo $url; ?>">
<?php
echo $taxonomy_term->name;
?>
</a>
</div>
</h3>

<?php endforeach; endif; ?>
 
$taxonomy_name = 'cate_jirei';
$taxonomys = get_terms($taxonomy_name,$args);

これだろう

あとは
フォーチでさらにクエリポストでまわした。





<?php
$args = array(
'parent'       => 0,
'hierarchical' => 0,
'orderby'      => 'term_order', // Category Order and Taxonomy Terms Order を使用
'order'        => 'ASC'
);
    $taxonomy_name = 'cate_jirei';
    $taxonomys = get_terms($taxonomy_name,$args);
    if(!is_wp_error($taxonomys) && count($taxonomys)):
        foreach($taxonomys as $taxonomy_term):
        $url = get_term_link($taxonomy_term->slug, $taxonomy_name);
?>



<h3><div class="jirei_title"><i class="icon-doc-inv"></i>
<a href="<?php echo $url; ?>">
<?php
echo $taxonomy_term->name;
?>
</a>
</div>
</h3>










<!----------------------BOX ALL----------------------------->

<div class="jirei_box_all">
<?php
$args = array(
		'posts_per_page' => -1,
//'orderby' => 'menu_order',
//'order' => 'ASC',
'tax_query' => array(
			'relation' => 'AND',
			array(
				'taxonomy' => $taxonomy_name,
				'field' => 'slug',
				'terms' => array( $taxonomy_term->slug ),
//'operator'=>'NOT IN'
				),
),
//カテ例 'cat'=> 4,
//カテ複数例	'cat'=> array(4,6)

	);
?>

<!----/宣言----->
<!----宣言2----->
<?php
	query_posts( $args );
?>


<!--★★★ループ基本-->
<?php
if ( have_posts () ) :
    while ( have_posts() ) :
        the_post();
?>



<div class="jirei_box">



<div class="jirei_box_img" style="height:210px;">

<a href="<?php the_permalink(); ?>">
 <?php
$title= get_the_title();
echo wp_get_attachment_image(get_post_meta($post->ID,"jirei_gazou",true),W210,0,array('alt'=>$title,'title'=>$title)); ?>
</a>

<?php //new
$days=30;
$today=date('U'); $entry=get_the_time('U');
$diff1=date('U',($today - $entry))/86400;
if ($days > $diff1) {
echo '<div class="new_icon"><img src="/img/new_icon/rainbow1.gif" width="31" height="12" alt="愛知春日井ホームページ制作NEW記事"></div>';
}
?>

</div>

<h4><div class="jirei_sub_title"><i class="icon-dot-circled"></i>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
</a></div></h4>


</div>
<?php
    endwhile;
endif;
?>
<?php wp_reset_query(); ?>


<div style="clear:both"></div>



</div class="jirei_box_all">

<div style="padding-top:30px;"></div>






<!----------------------BOX ALL----------------------------->















 
 
 
 
<?php endforeach; endif; ?>

原文はこうだ

<?php
$args = array(
'parent'       => 0,
'hierarchical' => 0,
'orderby'      => 'term_order', // Category Order and Taxonomy Terms Order を使用
'order'        => 'ASC'
);
    $taxonomy_name = 'item_category';
    $taxonomys = get_terms($taxonomy_name,$args);
    if(!is_wp_error($taxonomys) && count($taxonomys)):
        foreach($taxonomys as $taxonomy):
        $url = get_term_link($taxonomy->slug, $taxonomy_name);
        $tax_posts = get_posts(array(
            'post_type' => get_post_type(),
            'posts_per_page' => 5, // 表示させたい記事数
            'tax_query' => array(
                array(
                    'taxonomy'=>'item_category',
                    'terms'=>array( $taxonomy->slug ), 
                    'field'=>'slug',
                    'include_children'=>true,
                    'operator'=>'IN'
                    ),
                'relation' => 'AND'
                )
            ));
    if($tax_posts):
?>
<h2 id="<?php echo esc_html($taxonomy->slug); ?>" class=""><a href="<?php echo $url; ?>"><?php echo esc_html($taxonomy->name); ?></a></h2>
<ul>
    <?php foreach($tax_posts as $tax_post): ?>
    <li>
        <span class="thumb">
            <a href="<?php echo get_permalink($tax_post->ID); ?>">
            <?php if(has_post_thumbnail($tax_post->ID)) {
                echo get_the_post_thumbnail($tax_post->ID,'post-thumbnail');
             } ?>
            </a>
        </span>
        <span class="title"><?php echo get_the_title($tax_post->ID); ?></span>
    </li>
    <?php endforeach; ?>
</ul>
<?php
        endif;
endforeach;
endif;
?>

さらにタクソノミー シーズンで表現

<?php
$args = array(
'parent'       => 0,
'hierarchical' => 0,
'orderby'      => 'term_order', // Category Order and Taxonomy Terms Order を使用
'order'        => 'ASC'
);
    $taxonomy_name = 'item_category';
    $taxonomys = get_terms($taxonomy_name,$args);
    if(!is_wp_error($taxonomys) && count($taxonomys)):
        foreach($taxonomys as $taxonomy):
        $url = get_term_link($taxonomy->slug, $taxonomy_name);
        $this_term = get_query_var( 'term' );
        $tax_posts = get_posts(array(
            'post_type' => get_post_type(),
            'posts_per_page' => 5, // 表示させたい記事数
            'tax_query' => array(
                array(
                    'taxonomy'=>'item_category',
                    'terms'=>array( $taxonomy->slug ), 
                    'field'=>'slug',
                    'include_children'=>true,
                    'operator'=>'IN'
                    ),
                array(
                    'taxonomy'=>'season',
                    'terms'=>array( $this_term ),
                    'field'=>'slug',
                    'include_children'=>true,
                    'operator'=>'AND'
                    ),
                'relation' => 'AND'
                )
            ));
    if($tax_posts):
?>
<h2 id="<?php echo esc_html($taxonomy->slug); ?>" class=""><a href="<?php echo $url; ?>"><?php echo esc_html($taxonomy->name); ?></a></h2>
<ul>
    <?php foreach($tax_posts as $tax_post): ?>
    <li>
        <span class="thumb">
            <a href="<?php echo get_permalink($tax_post->ID); ?>">
            <?php if(has_post_thumbnail($tax_post->ID)) {
                echo get_the_post_thumbnail($tax_post->ID,'post-thumbnail');
             } ?>
            </a>
        </span>
        <span class="title"><?php echo get_the_title($tax_post->ID); ?></span>
    </li>
    <?php endforeach; ?>
</ul>
<?php
        endif;
endforeach;
endif;
?>

さらにこの記事に書くが
何件以上あった場合には 全て表示を表示したい

まずタームなので

上記コードの

$taxonomys = get_terms($taxonomy_name,$args);
を使い

$count = $taxonomy_term->count;

とし

それで分岐 wp_reset_queryの前

リンク先は

$url = get_term_link($taxonomy_term->slug, $taxonomy_name);

を使いそのままえこー

演算子はここを参照
http://www.tohoho-web.com/js/operator.htm

<?php if($count > 9):
?>

<div style="text-align:right; padding-top:0px; padding-bottom:15px; padding-right:30px;">
   <a href="<?php echo $url; ?>" style="color:#FF3300; font-size:13px;">すべて見る ▶▶</a>
    </div>
    
<?php
endif;
?>

参考

タームIDで記事数取得:
get_term( $chosen_id, 'タクソノミースラッグ' )->count

タームスラッグで記事数取得:
get_term_by( 'slug', 'タームスラッグ', 'タクソノミースラッグ' )->count

参照:codex.wordpress.org
get_term
get_term_by

カテゴリは

get_category($id)->category_count;

これらしい
未検証

わかった事 記事並び替え

まず
検索結果を並び替える場合

if ($query->is_search() ) ://method=”post” URLが動的
$sortset = (string)filter_input(INPUT_POST, ‘sort’);

としなかん 
つまり 
新しく覚えた get と post の違いがあり
getはページ送りできて
postはできやん

じゃあgetでいいやんと思うが
検索結果のURLは動的URLだで

getじゃとれんみたい
だでpostならとれた

だで
ファンクションのgetもサーチだけポストにしたらできた

試しにテキストだけで400件位読み込んでみたげ大丈夫か
画像は徐々に読み込ますjsいれるか?

つまり全件表示
もしそうでないくて良い場合
できるなら
検索結果のURLを変更 最後/にする

method=”post” でページ送り クッキーつかうとできるとかできんとかな?
そんぐらいか?

スクロールで車どんどんだすなら

Infinite-Scroll

簡単

こいつ入れて
設定するだけ

Contact form 7 のフォームに自動的に記事タイトルを入れる方法

function my_form_tag_filter($tag){
  if ( ! is_array( $tag ) )
  return $tag;
 
  if(isset($_GET['carname_title'])){
    $name = $tag['name'];
    if($name == 'carname_title')
      $tag['values'] = (array) $_GET['carname_title'];
  }
  return $tag;
}
add_filter('wpcf7_form_tag', 'my_form_tag_filter', 11);

carname_titleを変える。

コンタクトに作成

<a href='/?page_id=9&carname_title=<?php the_title(); ?>'>

二つの場合

//Contact form 7 のフォームに自動的に記事タイトルを入れる方法
function my_form_tag_filter($tag){
  if ( ! is_array( $tag ) )
  return $tag;
 
  if(isset($_GET['carname_title'])){
    $name = $tag['name'];
    if($name == 'carname_title')
      $tag['values'] = (array) $_GET['carname_title'];
  }
  
      if(isset($_GET['car_url'])){
    $name = $tag['name'];
    if($name == 'car_url')
      $tag['values'] = (array) $_GET['car_url'];
  }
  
  return $tag;
 
}
add_filter('wpcf7_form_tag', 'my_form_tag_filter', 11);

スペシャルコード 親要素 小要素がすべてアブソルートの場合の縦横比固定のレスポンシブ ギャラリーのレスポンシブで仕様方法

写真 写真 写真

この場合
cssで
縦横指定
100%
autoでは
親の高さが指定しないと
レスポンシブされない。

そのための対応策として
無地もしくは透明な画像を
アブソルートの下にダミーで敷く

写真 写真 写真

とし 画像はギャラリーの枠のDIVと同じ比率に 透明もしくは白だが

そして
.d-garabox{ width: 100%;height: auto; }

とすればよい

アーカイブページ等の記事の並び替え方法

参考 http://ateitexe.com/wordpress-archive-sort-popular/

まずパーマーリンクを
投稿名にしなければならん

ポストタイプアーカイブ
http://www.d-format1.com/car/
のようにケツにスラッシュで終わらなかん


固定ページでは
is_main_くえり がポストタイプを指定できなかったな〜
カスタムポストでなく ポストならできるかも

URLに
?sort=newerのように

?自分できめた文字=自分で決めた文字

というURLをつけるように

ボタンをつくる。

簡単にコードをまとめたやつを書こう

<?php
if ( is_archive() || is_search() ) { //アーカイブか検索ページだったら
    global $wp_query;
    $total_results = $wp_query->found_posts; //件数を取得しておく
	
//※ソールドアウトの設定確認
}
?>
 



   
</div></h2>



<?php //※1 2ページ目以降でボタンを押されても、1ページ目に飛ぶようにURLを指定
$url = explode('/', $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$url_str ='http://'.$url[0].'/'.$url[1].'/';
$sortset = (string)filter_input(INPUT_GET, 'sort'); //信頼できないのでチェック
?>

<div class="change_bottan_arc">

取り扱い車両:<?php echo $total_results; ?>件<br />

並び替え:
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="newer"/>
    <input type="submit" value="新着順" />
</form>
</form>
<!--|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="older"/>
    <input type="submit" value="古い" />
</form>-->
|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_price_low"/>
    <input type="submit" value="価格が安い" />
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_price_high"/>
    <input type="submit" value="価格が高い" />
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_km_low"/>
    <input type="submit" value="走行距離が短い" />
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_year_new"/>
    <input type="submit" value="年式が新しい" />
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_cc_big"/>
    <input type="submit" value="排気量大" />
</form>
|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_cc_small"/>
    <input type="submit" value="排気量小" />
</form>
</div>
    <input type="hidden" name="sort" value="newer"/>
    <input type="submit" value="新着順" />

この部分が基本

あとは

ファンクションに

イズメインクエリを指定してやる

//こっから本番
function SortArchive( $query ) {
 //管理画面スルー	
    if ( is_admin() || ! $query->is_main_query() )
        return;
 //こっから
    if ( $query->is_category() || $query->is_archive() ) {
        $sortset = (string)filter_input(INPUT_GET, 'sort');
        //if ( $sortset != 'older' && $sortset != 'car_price_high' && $sortset != 'car_price_low' ) {
		if ( $sortset == 'new' ) {
            $query->set( 'orderby', 'date' ); //新しい デフォ
        } 
		elseif ( $sortset == 'older' ) { //記事古い
            $query->set( 'orderby', 'date' );
            $query->set( 'order', 'ASC' );
        } 
		elseif ( $sortset == 'car_price_high' ) { //価格高い
            $query->set( 'meta_key', 'car_price' );
            $query->set( 'orderby', 'meta_value_num' );
        } 
		elseif ( $sortset == 'car_price_low' ) { //安い
            $query->set( 'meta_key', 'car_price' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
        }
		
			elseif ( $sortset == 'car_km_low' ) { //走行距離が短い
            $query->set( 'meta_key', 'car_km' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
        }
		
			elseif ( $sortset == 'car_year_new' ) { //年式が新しい
            $query->set( 'meta_key', 'car_year' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'DESC' );
        }
		
			elseif ( $sortset == 'car_cc_big' ) { //排気量大
            $query->set( 'meta_key', 'car_cc' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'DESC' );
        }
		
			elseif ( $sortset == 'car_cc_small' ) { //排気量小
            $query->set( 'meta_key', 'car_cc' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
        }
        return;
    }
}
add_action( 'pre_get_posts', 'SortArchive' );

こうだ!

空のカスタムフィールどの場合の表示は無視してそのままでるからそこは
制御してない

あとは

カレントを設定するコードを書いたらOKか?

こうした↓
デフォのアーカイブも新着がかれんとされるようにね

<?php //※1 2ページ目以降でボタンを押されても、1ページ目に飛ぶようにURLを指定
$url = explode('/', $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$url_str ='http://'.$url[0].'/'.$url[1].'/';
$sortset = (string)filter_input(INPUT_GET, 'sort'); //信頼できないのでチェック
?>

<div class="change_bottan_arc">

取り扱い車両:<?php echo $total_results; ?>件<br />

並び替え:
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="newer"/>
<?php if ( $sortset == 'newer' || $sortset == '' ): ?>
    <input type="submit" class="sort_current" value="新着順" />
<?php else: ?>
    <input type="submit" value="新着順" />
<?php endif; ?>
</form>
</form>
<!--|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="older"/>
    <input type="submit" value="古い" />
</form>-->
|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_price_low"/>
    <?php if ( $sortset == 'car_price_low' ): ?>
    
    <input type="submit" value="価格が安い"  class="sort_current" />
    <?php else: ?>
    <input type="submit" value="価格が安い" />
    <?php endif; ?>
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_price_high"/>
    <?php if ( $sortset == 'car_price_high' ): ?>
    <input type="submit" value="価格が高い"  class="sort_current" />
        <?php else: ?>
        <input type="submit" value="価格が高い" />
    <?php endif; ?>
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_km_low"/>
    <?php if ( $sortset == 'car_km_low' ): ?>
    <input type="submit" value="走行距離が短い"  class="sort_current" />
        <?php else: ?>
        <input type="submit" value="走行距離が短い" />
    <?php endif; ?>
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_year_new"/>
    <?php if ( $sortset == 'car_year_new' ): ?>
    <input type="submit" value="年式が新しい"  class="sort_current" />
        <?php else: ?>
         <input type="submit" value="年式が新しい" />
    <?php endif; ?>
</form>

|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_cc_big"/>
    <?php if ( $sortset == 'car_cc_big' ): ?>
    <input type="submit" value="排気量大"  class="sort_current" />
        <?php else: ?>
        <input type="submit" value="排気量大" />
    <?php endif; ?>
</form>
|
<form method="get" action="<?php echo $url_str //※1?>">
    <input type="hidden" name="sort" value="car_cc_small"/>
    <?php if ( $sortset == 'car_cc_small' ): ?>
    <input type="submit" value="排気量小"  class="sort_current" />
        <?php else: ?>
        <input type="submit" value="排気量小" />
    <?php endif; ?>
</form>

cssも書いとく

/*-----------------------並べ替えボタン*/

.change_bottan_arc{ margin-top:20px; margin-bottom:10px;font-size: 80%;}

.change_bottan_arc form{display: inline!important;}

.change_bottan_arc input[type='submit']{
color: #aa9a85;
    padding: 0;
    margin: 0;
    box-shadow: none!important;
    background: none!important;
    border: none!important;
font-size: 100%;
    text-decoration: underline;
    cursor: pointer;
	}
.change_bottan_arc .sort_current{ font-weight: normal!important;
    text-decoration: none!important;
	color:#e60012!important}

投稿日や更新日のクエリdate_query

タックスクエリ
メタクエリ
に続き
発見しましたよ
date_query

クエリポストや
イズメインクエリなどで
重宝しそう

今回の目的は
ソールドアウトと更新した記事は
30日間はループに表示させるが
30日以降は表示させない

という設定で仕様予定

date_query

//投稿日が一年以上前で、一ヶ月以内に更新された記事を取得

$args = array(
	'date_query' => array(
		array(
			'column' => 'post_date_gmt',
			'before' => '1 year ago',
		),
		array(
			'column' => 'post_modified_gmt',
			'after'  => '1 month ago',
		),
	),
	'posts_per_page' => -1,
);
$query = new WP_Query( $args );

省略時は投稿日時(’post_date’)となっている。’column’には’post_date’、’post_date_gmt’、’post_modified’、’post_modified_gmt’、’comment_date’、’comment_date_gmt’が指定できる。

$query = new WP_Query(
array(
‘date_query’=>array(
array(
‘inclusive’=>ture,
‘after’=>date(‘Y/m/d’, strtotime(‘-14 days’)))
)
)
);

http://www.mspace.info/wordpress-4-251.html

くわしくは
http://codex.wordpress.org/Class_Reference/WP_Query

参考

http://elearn.jp/wpman/column/c20131030_01.html

以下
コードの参照になればとコピペ

//サイトを閲覧している日時に更新されたpostを取得

$today = getdate();
$args = array(
	'date_query' => array(
		array(
			'year'  => $today["year"],
			'month' => $today["mon"],
			'day'   => $today["mday"],
		),
	),
);
$query = new WP_Query( $args );


//今週の記事を取得

$week = date('W');
$year = date('Y');
$query = new WP_Query( 'year=' . $year . '&w=' . $week );

//今週の記事を取得

$args = array(
	'date_query' => array(
		array(
			'year' => date('Y'),
			'week' => date('W'),
		),
	),
);
$query = new WP_Query( $args );


日〜土が1〜7に割り当てられています。
日 = 1
月 = 2
火 = 3
水 = 4
木 = 5
金 = 6
土 = 7

//平日(月〜金)9時〜17時に投稿された記事を取得

$args = array(
	'date_query' => array(
		array(
			'hour'      => 9,
			'compare'   => '>=',
		),
		array(
			'hour'      => 17,
			'compare'   => '<=',
		),
		array(
			'dayofweek' => array( 2, 6 ),
			'compare'   => 'BETWEEN',
		),
	),
	'posts_per_page' => -1,
);
$query = new WP_Query( $args );




ソースを見ているとcompareには下記の値が使えそうです。BETWEEN、NOT BETWEENあたりは特に便利そうですね。

'=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'




続いてもう一つ。afterのように英語表記で年月日指定もできますが、beforeのような指定のほうがわかりやすいと思います。
inclusiveはafter, beforeのみに適用されるtrue/falseの値を取るパラメータで、trueであればafterやbefore自体のマッチした投稿を含む、falseであれば含まない、というパラメータになっています。

//2013/1/1〜2013/2/28に投稿された記事を取得

$args = array(
	'date_query' => array(
		array(
			'after'     => 'January 1st, 2013',
			'before'    => array(
				'year'  => 2013,
				'month' => 2,
				'day'   => 28,
			),
			'inclusive' => true,
		),
	),
	'posts_per_page' => -1,
);
$query = new WP_Query( $args );

http://makeityourself.org/howto/date_query/

クエリーポストまとめURL等

http://blog.sus-happy.net/201105/customfield-search/

meta_key と meta_value
meta_compare 

「meta_compare」に、「=」(デフォルト)、「!=」、「>」、「>=」、「<」、「<」の指定をして異なる検索結果を得ることが出来ます。 meta_query 以下のように記述することで、「hoge」に「fuga」という文字列を含み、「foo」(配列)の値が「bar」を持たない記事を検索できます。 条件式の「compare」も追加されており、「LIKE」、「NOT LIKE」、「IN」、「NOT IN」、「BETWEEN」、「NOT BETWEEN」という曖昧な検索を行えるようになりました。 [php] query_posts( array( "meta_query" => array( array( "key" => "hoge", "value" => "fuga", "compare" => "LIKE" ), array( "key" => "foo", "value" => "bar", "compare" => "NOT IN" ) ) ) );[/php] 複数ソート むりくる http://www.seeds-std.co.jp/seedsblog/876.html http://globalit-academy.com/programming/wordpress%E3%81%A7%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%82%92%E5%AF%BE%E8%B1%A1%E3%81%AB%E3%82%BD%E3%83%BC%E3%83%88%E3%81%99/

wp-custom-fields-search で各項目にクラスをつけるコード

昔使った 繰り返せば増えるコードを使用

wp-custom-fields-search-form.php

<?php if($title && !(@$params['noTitle'])){
	echo $params['before_title'].$title.$params['after_title'];
}?>
	<form method='get' class='<?php echo $formCssClass?>' action='<?php echo $formAction?>'>
<?php echo $hidden ?>
		<div class='searchform-params'>
        
        
<?php $i = 1; // 追加?>
<?php		foreach($inputs as $input){?>
<div class='<?php echo $input->getCSSClass()?> car_search<?php echo $i++; // 追加?>'><?php echo $input->getInput()?></div>
<?php		}?>
</div>
<div class='searchform-controls'>

<input type='submit' name='search' value='<?php _e('Search','wp-custom-fields-search')?>'/>
</div>
<?php if(array_key_exists('showlink',$config) && $config['showlink']) { ?>
<div class='searchform-spoiler'><?php echo $spoiler_link; ?></div>
<?php } ?>
</form>

Jクエリで管理画面の順番を入れ替えるコード

おきかえはよくあるので
調べたので忘れない様に解説します。

function my_footer() {
}
add_action('admin_footer', 'my_footer');
で管理画面フッターに入れます。


echo '<script type="text/javascript">
  </script>';

でスプリクトを差し込みます。

  //<![CDATA[
  //]]>

はCDATA セクションというらしく
ここにの文字は純粋な文字として処理されるそう。
http://wisdom.sakura.ne.jp/web/xml/xml/xml7.html参考

そして
jQuery(function(){
});
JQueryの実行?

ポイント
----------------------------------------------------------
$(A).prepend(B) はA要素の最後にB要素が追加される
要素の中身を他の要素の先頭に挿入する。

■具体的に最後に挿入したい場合一度とりだしてまた入れると最後に入れられる
(これは、全ての要素に対して appendChild を行うことに近く、
操作後はDOMに要素が追加された状態になる。らしい。
(多分たくさんあれば全部にいれるってこと?))


$(A).prependTo(B) ではB要素にA要素が挿入される。


$(A).append(B) A要素の最初にB要素が追加される

$(A).appendTo(B) B要素の最初にA要素が追加される
----------------------------------------------------------

jQuery("#normal-sortables").prepend( jQuery("#acf_497") ); 
でエディターの次のDIV#normal-sortables の先頭にアドバンスカスタムのBOXを



// カテゴリ->カスタムフィールド->公開 に毎回並び替える
function my_footer() {
echo '<script type="text/javascript">
  //<![CDATA[
  jQuery(function(){
	  
	  
	jQuery("#normal-sortables").prepend( jQuery("#acf_497") ); 	  



こいつらはつかわせんけど記録用
jQuery("#normal-sortables").prepend( jQuery("#side-sortables").children("#tagsdiv-car_name") ); 
jQuery("#tagsdiv-car_name").prependTo(jQuery("#normal-sortables"));
jQuery("#normal-sortables").append(jQuery("#side-sortables").children("#submitdiv"));
jQuery("#submitdiv").appendTo(jQuery("#normal-sortables"));
  });
  //]]>
  </script>';
}
add_action('admin_footer', 'my_footer');

//prependは先頭に挿入

記事一覧の並び替え

参考

http://blog.anekipedia.com/cus/%E8%A8%98%E4%BA%8B%E4%B8%80%E8%A6%A7%E3%82%92%E3%82%BD%E3%83%BC%E3%83%88%EF%BC%88%E4%B8%A6%E3%81%B3%E6%9B%BF%E3%81%88%EF%BC%89%E3%81%99%E3%82%8B.html

http://ateitexe.com/wordpress-archive-sort-popular/

http://takahashifumiki.com/web/programing/1829/

カスタムフィールドのキーを出力できて リンク先を指定できるプラグイン

Custom Field List

ウィジェッットで使用

きーを選んで通常だと
そのキーの記事が出てくるが
リンクの設定をすると
その先を全て指定できる

デフォルトはなにもはいってない
えらーになるので
指定して保存

S=naninanai と検索なので
サーチエブリシング

もしくは
?s=春日井市&post_type=jirei

なども
&order=ASC
など自分でコード書く

検索結果にカスタム投稿も含ませる

/ 検索結果から固定ページを除外
function search_filter($query) {
  if (!$query -> is_admin && $query -> is_search) {
    $query -> set('post_type', array('post','asobu','share','seikatsu','iryou','manabu','koukyou','ofuroyado'));
  }
  return $query;
}
add_filter('pre_get_posts', 'search_filter');
function filter_search($query) {
    if ($query->is_search) {
	$query->set('post_type', array('post', 'hogehoge'));
    };
    return $query;
};
add_filter('pre_get_posts', 'filter_search');

こんなコードあったが必要なのかどうか今はいらない?

カスタムポストUIに
検索結果から除外する ture false があったが
かわったのか???
未深検証

検索結果 調整 WP Custom Fields Search

まず問題だったこと
それは
古いコードがファンクションに書いてあったため複雑になった。

/ 検索結果から固定ページを除外
function search_filter($query) {
  if (!$query -> is_admin && $query -> is_search) {
    $query -> set('post_type', array('post','asobu','share','seikatsu','iryou','manabu','koukyou','ofuroyado'));
  }
  return $query;
}
add_filter('pre_get_posts', 'search_filter');

つまりポストタイプを指定して固定ページを除外してた 多分

これをまず消す。

これで多分ポストタイプ関係無しに検索できるはず

サーチエブリシングを入れる。

これでカスタムフィールドの文字も検索できるはず。

ただし絞り込みプラグインで
ポストタイプを指定する時
and or が指定できない気がする。

サーチページで分岐できれば必要ないが。。

ポストタイプを指定する方法。

–引用—-
● フィールド1つ目の設定内容
このフィールドでやっている事。
・検索は、カスタム投稿「post-typea」の中から行うようにする
—–
データタイプ:「Post Type」を指定
—–
ウィジェット:「非表示の定数」を指定
Post Typeは、ユーザーが指定するものではないので、このフィールドは表示されません。
比較:同等
—–
ウィジェットの設定:post-typea
—–

● フィールド2つ目の設定内容
このフィールドでやっている事。
・検索条件は、カスタムフィールドの登録値をプルダウンで表示するようにする。
—–
データタイプ:「カスタムフィールド」を指定
—–
ウィジェット:「ドロップダウン」を指定
指定のカスタムフィールドに登録されている値がドロップダウンとなって表示する
—–
比較:同等
—–