WordPress初心者です。
カスタム投稿タイプで登録したお店の検索機能を作っているのですが、どうしても3ページ目で404が出てしまいます。
3ページ目で404が出る事例がなかなか見つからず、困っております。
サンプルを切り貼りしているため、どこか間違っているのかもしれませんので、ご指定いただけますと幸いですm(_ _)m
php
1 <?php 2 $city = get_post(get_the_ID())->area_city; 3 global $wpdb; 4 // If you use a custom search form 5 // $keyword = sanitize_text_field( $_POST['keyword'] ); 6 // If you use default WordPress search form 7 $keyword = get_search_query(); 8 $keyword = '%' . $wpdb->esc_like( $keyword ) . '%'; // Thanks Manny Fleurmond 9 // Search in all custom fields 10 $post_ids_meta = $wpdb->get_col( $wpdb->prepare( " 11 SELECT DISTINCT post_id FROM {$wpdb->postmeta} 12 WHERE meta_value LIKE '%s' 13", $keyword ) ); 14 // Search in post_title and post_content 15 $post_ids_post = $wpdb->get_col( $wpdb->prepare( " 16 SELECT DISTINCT ID FROM {$wpdb->posts} 17 WHERE post_title LIKE '%s' 18 OR post_content LIKE '%s' 19", $keyword, $keyword ) ); 20// $post_ids = $post_ids_meta; 21 $post_ids = array_merge( $post_ids_meta, $post_ids_post ); 22 23 $args = Array( 24 'post_type' => 'shop', 25 'posts_per_page' => 10, 26 'paged' => $paged, 27 'post__in' => $post_ids 28 ); 29 30 $temp = $wp_query; 31 $wp_query = null; 32 if(!empty($post_ids)) { 33 $wp_query = new WP_Query($args); 34 } 35 else { 36 $wp_query = new WP_Query(); 37 } 38 //検索件数 39// global $wp_query; 40 $total_results = $wp_query->found_posts; 41 ?> 42 43 <article class="search-result"> 44 <header class="article-header"> 45 <h1 class="page-title" itemprop="headline"> 46 <?php 47 if($total_results > 0) { 48 echo $total_results . '件のお店が見つかりました'; 49 } 50 else { 51 echo 'お店が見つかりませんでした'; 52 } 53 54 ?> 55 </h1> 56 </header> <?php // end article header ?> 57 <section class="entry-content cf" itemprop="articleBody"> 58 59 60 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 61 <article id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting"> 62 <section class="entry-content cf" itemprop="articleBody"> 63 <article class="shop-info"> 64 <header> 65 <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 66 </header> 67 <section> 68 <ul> 69 <li> 70 <dl> 71 <dt><strong>店舗名</strong></dt> 72 <dd><?php echo get_post_meta($post->ID, 'shop_name', true); ?></dd> 73 </dl> 74 </li> 75 <li> 76 <dl> 77 <dt><strong>住所</strong></dt> 78 <dd><?php echo get_post_meta($post->ID, 'shop_address', true); ?></dd> 79 </dl> 80 </li> 81 <li> 82 <dl> 83 <dt><strong>電話番号</strong></dt> 84 <dd><?php echo get_post_meta($post->ID, 'shop_tel', true); ?></dd> 85 </dl> 86 </li> 87 <li> 88 <dl> 89 <dt><strong>営業時間</strong></dt> 90 <dd><?php echo get_post_meta($post->ID, 'shop_time', true); ?></dd> 91 </dl> 92 <dl> 93 <dt><strong>定休日</strong></dt> 94 <dd><?php echo get_post_meta($post->ID, 'shop_holiday', true); ?></dd> 95 </dl> 96 </li> 97 <li> 98 <dl> 99 <dt><strong>ホームページ</strong></dt> 100 <dd><a href="<?php echo get_post_meta($post->ID, 'shop_url', true); ?>"><?php echo get_post_meta($post->ID, 'shop_url', true); ?></a></dd> 101 </dl> 102 </li> 103 </ul> 104 </section> 105 </article> 106 107 108 109 </section> <?php // end article section ?> 110 111 <!-- <footer class="article-footer cf">--> 112 <!-- </footer>--> 113 114<!-- --><?php //comments_template(); ?> 115 </article> 116 117 118 <?php endwhile;?> 119 <nav class="pagenav"> 120 <span><?php previous_posts_link(); ?></span> 121 <span><?php next_posts_link(); ?></span> 122 </nav> 123 <?php else: ?> 124 <article> 125 <p>検索キーワードを変更してやり直してください。</p> 126 <?php get_search_form(); ?> 127 </article> 128 129 <?php endif; ?> 130 <?php $wp_query = null; $wp_query = $temp; ?> 131 132 </section> 133 </article> 134
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。