<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>検索機能 &#8211; ケケンタの独学ITブログ</title>
	<atom:link href="https://kekenta-it-blog.com/tag/%E6%A4%9C%E7%B4%A2%E6%A9%9F%E8%83%BD/feed/" rel="self" type="application/rss+xml" />
	<link>https://kekenta-it-blog.com</link>
	<description>プログラミングやWeb制作の情報を発信</description>
	<lastBuildDate>Tue, 18 Mar 2025 02:08:16 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://kekenta-it-blog.com/wp-content/uploads/2023/07/cropped-KEKENTA-BLOG-32x32.png</url>
	<title>検索機能 &#8211; ケケンタの独学ITブログ</title>
	<link>https://kekenta-it-blog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【WordPress】検索結果から固定ページを除外する方法【コピペで簡単！】</title>
		<link>https://kekenta-it-blog.com/wp-search-exc-page/</link>
					<comments>https://kekenta-it-blog.com/wp-search-exc-page/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Thu, 15 Aug 2024 05:24:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[固定ページ]]></category>
		<category><![CDATA[検索機能]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=10153</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-exc-page__10153-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>WordPressでは簡単に検索機能を実装することが可能です。 ただ、その検索対象はデフォルトだと投稿・固定ページの「タイトル」と「本文」に設定されており、必要に応じて自分自身で検索対象をカスタマイズする必要があります。 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-exc-page__10153-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>
<p>WordPressでは簡単に検索機能を実装することが可能です。</p>



<p class="is-style-bg_stripe">ただ、その検索対象はデフォルトだと<strong>投稿・固定ページの「タイトル」と「本文」</strong>に設定されており、必要に応じて自分自身で検索対象をカスタマイズする必要があります。</p>



<p>この記事ではそうしたカスタマイズの内、</p>



<p class="has-text-align-center is-style-big_kakko_box"><strong><span class="swl-marker mark_yellow">検索結果から固定ページを除外する方法</span></strong></p>



<p>をご紹介します。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>コピペで簡単にカスタマイズできるのでぜひお試しください！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-subloop-wq/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】WP_Query（サブループ）の使い方とパラメータ一覧を紹介</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2025/03/eye-catch__school-php-and-wp__14099-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/school-php-and-wp/">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</a>
						<span class="p-blogCard__excerpt">僕はこれまで独学でPHPを学習してきました。結論から言えば、それでもPHPを習得することはできました。 しかし、それに費やした累計学習期間は1年ほど。モチベーション&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">【ソースコード】検索結果から固定ページを除外する</h2>



<p class="is-style-bg_stripe">以下のソースコードを<strong>functions.phpへ追記</strong>します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>add_action( &#39;pre_get_posts&#39;, function( $query ) ) {
    // 「管理画面」や「メインクエリ以外」には適用しない
    if ( is_admin() || ! $query-&gt;is_main_query() ) {
        return;
    }

    // 検索対象ページを「投稿」のみにする
    if ( $query-&gt;is_search() ) {
        $query-&gt;set( &#39;post_type&#39;, &#39;post&#39; );
        return;
    }
}</code></pre></div>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>たったこれだけでWordPressの検索機能の検索対象から「固定ページ」を除外することが可能です！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<h2 class="wp-block-heading">まとめ</h2>



<p>WordPressで検索機能を実装すること自体はそれほど難しくありません。</p>



<p>しかし、細かい検索条件などを調整するとなった場合は今回のようにfunctions.php上でソースコードを記述する必要があります。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>当記事以外にも「検索機能」に関する記事を公開しています。<br>ご興味のある方はぜひご覧いただけるとうれしいです！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>

<div class="p-blogParts post_content" data-partsID="10168">
<p class="is-style-balloon_box"><strong>検索機能の関連記事</strong></p>


<div class="p-postListWrap"><ul class="p-postList -type-simple"><li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-exc-page/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-15" aria-label="公開日">2024-08-15</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索結果から固定ページを除外する方法【コピペで簡単！】</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom-ssp/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-07" aria-label="公開日">2024-08-07</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-02" aria-label="公開日">2024-08-02</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-create-search/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-06-26" aria-label="公開日">2024-06-26</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能と検索結果ページを作成する方法</h2>		</div>
	</a>
</li>
</ul></div></div>]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-search-exc-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</title>
		<link>https://kekenta-it-blog.com/wp-search-condition-custom-ssp/</link>
					<comments>https://kekenta-it-blog.com/wp-search-condition-custom-ssp/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Wed, 07 Aug 2024 05:44:21 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[SEO SIMPLE PACK]]></category>
		<category><![CDATA[検索機能]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=9612</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom-ssp__9612-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>今回はこのようなお悩みをお持ちの方に向けて WordPressで検索機能の条件にSEO SIMPLE PACKの設定内容を追加するためのカスタマイズ方法 をご紹介します。 「タグ・カテゴリー・カスタムフィールド」を検索条 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom-ssp__9612-1024x576.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>WordPressの検索機能の条件に「SEO SIMPLE PACKの設定内容」も含めたいんだけど、どうすればいいの……？</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>今回はこのようなお悩みをお持ちの方に向けて</p>



<p class="has-text-align-center is-style-big_kakko_box"><strong>WordPressで検索機能の条件に</strong><br><strong>SEO SIMPLE PACKの設定内容を追加するためのカスタマイズ方法</strong></p>



<p>をご紹介します。</p>



<p class="is-style-balloon_box">「タグ・カテゴリー・カスタムフィールド」を検索条件に追加したい方はこちらをご覧ください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom__9607-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-search-condition-custom/">【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</a>
						<span class="p-blogCard__excerpt">WordPressの検索機能に条件を追加したいんだけどどうすればいいんだろう…… 今回はこうしたお悩みをお持ちの方へ向けて WordPressの検索機能の条件にタグ・カテゴリー・&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>WordPressの検索機能は簡単に実装可能ですが、デフォルトだと、投稿記事と固定ページの「タイトル」と「本文」しか検索対象に含まれていません。</p>



<p>しかし、<strong>SQLを利用することで複雑な検索条件を指定することが可能</strong>です。</p>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/school-php-and-wp/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</span>
			</a>
		</div>


<h2 class="wp-block-heading">【ソースコード】検索条件に<strong>SEO SIMPLE PACKの設定内容を追加する</strong></h2>



<p class="is-style-bg_stripe">以下のソースコードをfunctions.phpに追加するだけで、検索条件に<strong>SEO SIMPLE PACKの設定内容を含める</strong>ことが可能です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP" data-line="25-37, 39-51"><code>/**
 * サイト内検索のカスタマイズ
 */
function custom_search($search, $wp_query) {
	global $wpdb;

	//検索ページ以外だったら終了
	if (!$wp_query-&gt;is_search)
		return $search;

	if (!isset($wp_query-&gt;query_vars))
		return $search;

	$search_words = explode(&#39; &#39;, isset($wp_query-&gt;query_vars[&#39;s&#39;]) ? $wp_query-&gt;query_vars[&#39;s&#39;] : &#39;&#39;);
	if ( count($search_words) &gt; 0 ) {
		$search = &#39;&#39;;
		foreach ( $search_words as $word ) {
			if ( !empty($word) ) {
				$search_word = $wpdb-&gt;prepare(&quot;%{$word}%&quot;);
				$search .= &quot; AND (
					-- 投稿タイトル
					{$wpdb-&gt;posts}.post_title LIKE &#39;{$search_word}&#39;
					-- 投稿コンテンツ
					OR {$wpdb-&gt;posts}.post_content LIKE &#39;{$search_word}&#39;
					-- 「タグ・カテゴリー」のSEO SIMPLE PACK設定情報
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct r.object_id
						FROM {$wpdb-&gt;term_relationships} AS r
						INNER JOIN {$wpdb-&gt;term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id
						INNER JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id
						INNER JOIN {$wpdb-&gt;termmeta} AS tm ON t.term_id = tm.term_id
						WHERE tm.meta_value LIKE &#39;{$search_word}&#39; 
							-- タイトル
							AND ( tm.meta_key = &#39;ssp_meta_title&#39;
								-- ディスクリプション 
								OR tm.meta_key = &#39;ssp_meta_description&#39; )
					)

					-- 「固定・投稿ページ」のSEO SIMPLE PACK設定情報
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct pm.post_id
						FROM {$wpdb-&gt;postmeta} AS pm
						INNER JOIN {$wpdb-&gt;posts} AS p ON pm.post_id = p.id
						WHERE pm.meta_value LIKE &#39;{$search_word}&#39; 
							-- タイトル
							AND ( pm.meta_key = &#39;ssp_meta_title&#39;
								-- ディスクリプション
								OR pm.meta_key = &#39;ssp_meta_description&#39;
								-- キーワード
								OR pm.meta_key = &#39;ssp_meta_keyword&#39; )
					)
				) &quot;;
			}
		}
	}
	return $search;
}
add_filter(&#39;posts_search&#39;,&#39;custom_search&#39;, 10, 2);</code></pre></div>



<p class="is-style-balloon_box">このソースコードでは、<strong>下記２つを検索条件に追加</strong>しています。</p>



<div class="wp-block-group has-border -border02"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><strong>「カテゴリー・タグ」</strong>で設定しているSEO SIMPLE PACKの情報（タイトル・ディスクリプション）</li>



<li><strong>「固定・投稿ページ」</strong>で設定しているSEO SIMPLE PACKの情報（タイトル・ディスクリプション・キーワード）</li>
</ul>
</div></div>



<p class="is-style-icon_pen">もしも<strong>いずれかの設定情報は検索条件に含めたくない</strong>という場合は、それぞれに関連するハイライト行を削除してお使いください。</p>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">まとめ</h2>



<p>以上が<strong><span class="swl-marker mark_yellow">WordPressで検索機能の条件にSEO SIMPLE PACKの設定内容を追加する方法</span></strong>でした。</p>



<p>SQLを利用しているため、もしかしたらハードルを感じる方もいらっしゃるかもしれませんが、上記のソースコードを丸っとfunctions.phpに追加していただくだけでOKなので、まずは一度お試ししてみてはいかがでしょうか。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>この記事が少しでもお役に立ったなら何よりです！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>このブログではWordPressやWeb制作、PHPに関する情報を発信しています。</p>



<p>ご興味のある方はぜひほかの記事もご覧いただけるとうれしいです！</p>


<div class="p-blogParts post_content" data-partsID="10168">
<p class="is-style-balloon_box"><strong>検索機能の関連記事</strong></p>


<div class="p-postListWrap"><ul class="p-postList -type-simple"><li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-exc-page/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-15" aria-label="公開日">2024-08-15</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索結果から固定ページを除外する方法【コピペで簡単！】</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom-ssp/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-07" aria-label="公開日">2024-08-07</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-02" aria-label="公開日">2024-08-02</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-create-search/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-06-26" aria-label="公開日">2024-06-26</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能と検索結果ページを作成する方法</h2>		</div>
	</a>
</li>
</ul></div></div>]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-search-condition-custom-ssp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</title>
		<link>https://kekenta-it-blog.com/wp-search-condition-custom/</link>
					<comments>https://kekenta-it-blog.com/wp-search-condition-custom/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Fri, 02 Aug 2024 02:30:29 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[カテゴリー]]></category>
		<category><![CDATA[タグ]]></category>
		<category><![CDATA[検索機能]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=9607</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom__9607-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>今回はこうしたお悩みをお持ちの方へ向けて WordPressの検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する方法 をご紹介します。 WordPressの検索機能はデフォルトだと「タイトル」と「本文」しか検 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom__9607-1024x576.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>WordPressの検索機能に条件を追加したいんだけどどうすればいいんだろう……</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>今回はこうしたお悩みをお持ちの方へ向けて</p>



<p class="has-text-align-center is-style-big_kakko_box"><strong>WordPressの<span class="swl-inline-color has-swl-deep-02-color">検索機能の条件</span>に<br><span class="swl-inline-color has-swl-deep-02-color">タグ・カテゴリー・カスタムフィールド</span>を追加する方法</strong></p>



<p>をご紹介します。</p>



<p class="is-style-bg_stripe">WordPressの検索機能はデフォルトだと「タイトル」と「本文」しか検索対象になっていません。<br>しかし、この記事をご覧いただくことで<strong><span class="swl-marker mark_yellow">タグ・カテゴリー・カスタムフィールドも検索対象にする方法やそのソースコード</span></strong>がわかります。</p>



<div class="swell-block-capbox cap_box is-style-shadow"><div class="cap_box_ttl"><span><span data-icon="LsLightbulb" data-id="0" style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJNMzIgNDYuNUgxNmMtMS4xIDAtMi0uOS0yLTJzLjktMiAyLTJoMTZjMS4xIDAgMiAuOSAyIDJzLS45IDItMiAyek00MS43IDE1LjlDNDEuMyAxMyA0MCAxMC4zIDM4LjIgOCAzNC41IDMuMiAyOSAuOCAyMy4xIDEgMTQgMS40IDYuNSA4LjkgNiAxOGMtLjMgNiAyLjQgMTEuNyA3LjIgMTUuNC41LjQuOC45LjggMS41djEuNmMwIDIuMiAxLjggNCA0IDRoMTJjMi4yIDAgNC0xLjggNC00VjM1YzAtLjYuMy0xLjIuOS0xLjcgNS4zLTQgOC0xMC42IDYuOC0xNy40em0tNy4xIDEuN2gtLjNjLS43IDAtMS4zLS41LTEuNS0xLjItLjctMy4yLTMuMi01LjctNi40LTYuMy0uOC0uMS0xLjQtLjktMS4yLTEuN3MuOS0xLjQgMS43LTEuMmM0LjQuOCA4IDQuMiA4LjkgOC42LjEuOC0uNCAxLjYtMS4yIDEuOHoiPjwvcGF0aD48L3N2Zz4=)" aria-hidden="true" class="swl-inline-icon"> </span><strong>この記事で分かること</strong></span></div><div class="cap_box_content">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li>検索機能に「タグ」、「カテゴリー」、「カスタムフィールド」を追加する方法</li>



<li>すべてではなく「特定のカスタムフィールド」のみ検索条件として追加する方法</li>
</ul>
</div></div>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>また、タグやカテゴリーの名前だけでなく、タグ・カテゴリーの<strong>「スラッグ」や「説明」</strong>を検索条件に追加する方法もあわせてご紹介します。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p><strong>プラグイン「SEO SIMPLE PACK」の設定情報を含める方法</strong>は以下の記事でご紹介しています。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-search-condition-custom-ssp__9612-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-search-condition-custom-ssp/">【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</a>
						<span class="p-blogCard__excerpt">WordPressの検索機能の条件に「SEO SIMPLE PACKの設定内容」も含めたいんだけど、どうすればいいの……？ 今回はこのようなお悩みをお持ちの方に向けて WordPressで検索機&#8230;</span>					</div>
				</div>
			</div>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-subloop-wq/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】WP_Query（サブループ）の使い方とパラメータ一覧を紹介</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/school-php-and-wp/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</span>
			</a>
		</div>


<h2 class="wp-block-heading">ソースコード</h2>



<p class="is-style-bg_stripe">以下よりご紹介するソースコードを<strong>functions.phpに追加するだけで検索機能に各条件を含めることが可能</strong>です。</p>



<h3 class="wp-block-heading"><strong>「タグ名」、「カテゴリー名」を検索条件に追加</strong></h3>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>/**
 * サイト内検索のカスタマイズ
 */
function custom_search( $search, $wp_query ) {
	global $wpdb;

	//検索ページ以外だったら終了
	if ( ! $wp_query-&gt;is_search )
		return $search;

    // 検索キーワードが未入力ならデフォルトの検索機能を呼び出す
	if ( ! isset( $wp_query-&gt;query_vars ) )
		return $search;

	// タグ名・カテゴリ名も検索対象にする
	$search_words = explode( &#39; &#39;, isset( $wp_query-&gt;query_vars[&#39;s&#39;] ) ? $wp_query-&gt;query_vars[&#39;s&#39;] : &#39;&#39; );
	if ( count( $search_words ) &gt; 0 ) {
		$search = &#39;&#39;;
		foreach ( $search_words as $word ) {
			if ( ! empty( $word ) ) {
				$search_word = $wpdb-&gt;prepare( &quot;%{$word}%&quot; );
				$search .= &quot; AND (
					-- 投稿タイトル
					{$wpdb-&gt;posts}.post_title LIKE &#39;{$search_word}&#39;
					-- 投稿コンテンツ
					OR {$wpdb-&gt;posts}.post_content LIKE &#39;{$search_word}&#39;
					-- タグ・カテゴリー名
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct r.object_id
						FROM {$wpdb-&gt;term_relationships} AS r
						INNER JOIN {$wpdb-&gt;term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id
						INNER JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id
						-- タグ・カテゴリー名
						WHERE t.name LIKE &#39;{$search_word}&#39;
					)
				) &quot;;
			}
		}
	}
	return $search;
}
add_filter( &#39;posts_search&#39;,&#39;custom_search&#39;, 10, 2 );</code></pre></div>



<h3 class="wp-block-heading"><strong>タグ・カテゴリーの「スラッグ」や「説明」を検索条件に追加</strong></h3>



<p class="is-style-bg_stripe"><strong>ハイライト行が追加</strong>されています。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP" data-line="35-38"><code>/**
 * サイト内検索のカスタマイズ
 */
function custom_search( $search, $wp_query ) {
	global $wpdb;

	//検索ページ以外だったら終了
	if ( ! $wp_query-&gt;is_search )
		return $search;

    // 検索キーワードが未入力ならデフォルトの検索機能を呼び出す
	if ( ! isset( $wp_query-&gt;query_vars ) )
		return $search;

	// タグ名・カテゴリ名やタグ・カテゴリーの「スラッグ」、「説明」も検索対象にする
	$search_words = explode( &#39; &#39;, isset( $wp_query-&gt;query_vars[&#39;s&#39;] ) ? $wp_query-&gt;query_vars[&#39;s&#39;] : &#39;&#39; );
	if ( count( $search_words ) &gt; 0 ) {
		$search = &#39;&#39;;
		foreach ( $search_words as $word ) {
			if ( ! empty( $word ) ) {
				$search_word = $wpdb-&gt;prepare( &quot;%{$word}%&quot; );
				$search .= &quot; AND (
					-- 投稿タイトル
					{$wpdb-&gt;posts}.post_title LIKE &#39;{$search_word}&#39;
					-- 投稿コンテンツ
					OR {$wpdb-&gt;posts}.post_content LIKE &#39;{$search_word}&#39;
					-- 「タグ・カテゴリー名」と「タグ・カテゴリー説明欄」
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct r.object_id
						FROM {$wpdb-&gt;term_relationships} AS r
						INNER JOIN {$wpdb-&gt;term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id
						INNER JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id
						-- タグ・カテゴリー名
						WHERE t.name LIKE &#39;{$search_word}&#39;
							-- タグ・カテゴリースラッグ
							OR t.slug LIKE &#39;{$search_word}&#39;
							-- デフォルト項目の「説明」
							OR tt.description LIKE &#39;{$search_word}&#39;
					)
				) &quot;;
			}
		}
	}
	return $search;
}
add_filter( &#39;posts_search&#39;,&#39;custom_search&#39;, 10, 2 );</code></pre></div>



<h3 class="wp-block-heading"><strong>「すべてのカスタムフィールド」を検索条件に追加</strong></h3>



<p class="is-style-bg_stripe"><strong>ハイライト行が追加</strong>されています。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP" data-line="40-45"><code>/**
 * サイト内検索のカスタマイズ
 */
function custom_search( $search, $wp_query ) {
	global $wpdb;

	//検索ページ以外だったら終了
	if ( ! $wp_query-&gt;is_search )
		return $search;

    // 検索キーワードが未入力ならデフォルトの検索機能を呼び出す
	if ( ! isset( $wp_query-&gt;query_vars ) )
		return $search;

	// タグ名・カテゴリ名・カスタムフィールド「説明」も検索対象にする
	$search_words = explode( &#39; &#39;, isset( $wp_query-&gt;query_vars[&#39;s&#39;] ) ? $wp_query-&gt;query_vars[&#39;s&#39;] : &#39;&#39; );
	if ( count( $search_words ) &gt; 0 ) {
		$search = &#39;&#39;;
		foreach ( $search_words as $word ) {
			if ( ! empty( $word ) ) {
				$search_word = $wpdb-&gt;prepare( &quot;%{$word}%&quot; );
				$search .= &quot; AND (
					-- 投稿タイトル
					{$wpdb-&gt;posts}.post_title LIKE &#39;{$search_word}&#39;
					-- 投稿コンテンツ
					OR {$wpdb-&gt;posts}.post_content LIKE &#39;{$search_word}&#39;
					-- 「タグ・カテゴリー名」と「タグ・カテゴリー説明欄」
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct r.object_id
						FROM {$wpdb-&gt;term_relationships} AS r
						INNER JOIN {$wpdb-&gt;term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id
						INNER JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id
						-- タグ・カテゴリー名
						WHERE t.name LIKE &#39;{$search_word}&#39;
							-- タグ・カテゴリースラッグ
							OR t.slug LIKE &#39;{$search_word}&#39;
							-- デフォルト項目の「説明」
							OR tt.description LIKE &#39;{$search_word}&#39;
					)
					-- すべてのカスタムフィールド
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct post_id
						FROM {$wpdb-&gt;postmeta}
						WHERE meta_value LIKE &#39;{$search_word}&#39;
					)
				) &quot;;
			}
		}
	}
	return $search;
}
add_filter( &#39;posts_search&#39;,&#39;custom_search&#39;, 10, 2 );</code></pre></div>



<h3 class="wp-block-heading">「特定のカスタムフィールド」を検索条件に追加</h3>



<p class="is-style-bg_stripe"><strong>ハイライト行が追加</strong>されています。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP" data-line="45-46"><code>/**
 * サイト内検索のカスタマイズ
 */
function custom_search( $search, $wp_query ) {
	global $wpdb;

	//検索ページ以外だったら終了
	if ( ! $wp_query-&gt;is_search )
		return $search;

    // 検索キーワードが未入力ならデフォルトの検索機能を呼び出す
	if ( ! isset( $wp_query-&gt;query_vars ) )
		return $search;

	// タグ名・カテゴリ名・カスタムフィールド「説明」も検索対象にする
	$search_words = explode( &#39; &#39;, isset( $wp_query-&gt;query_vars[&#39;s&#39;] ) ? $wp_query-&gt;query_vars[&#39;s&#39;] : &#39;&#39; );
	if ( count( $search_words ) &gt; 0 ) {
		$search = &#39;&#39;;
		foreach ( $search_words as $word ) {
			if ( ! empty( $word ) ) {
				$search_word = $wpdb-&gt;prepare( &quot;%{$word}%&quot; );
				$search .= &quot; AND (
					-- 投稿タイトル
					{$wpdb-&gt;posts}.post_title LIKE &#39;{$search_word}&#39;
					-- 投稿コンテンツ
					OR {$wpdb-&gt;posts}.post_content LIKE &#39;{$search_word}&#39;
					-- 「タグ・カテゴリー名」と「タグ・カテゴリー説明欄」
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct r.object_id
						FROM {$wpdb-&gt;term_relationships} AS r
						INNER JOIN {$wpdb-&gt;term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id
						INNER JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id
						-- タグ・カテゴリー名
						WHERE t.name LIKE &#39;{$search_word}&#39;
							-- タグ・カテゴリースラッグ
							OR t.slug LIKE &#39;{$search_word}&#39;
							-- デフォルト項目の「説明」
							OR tt.description LIKE &#39;{$search_word}&#39;
					)
					-- カスタムフィールド
					OR {$wpdb-&gt;posts}.ID IN (
						SELECT distinct post_id
						FROM {$wpdb-&gt;postmeta}
						WHERE meta_value LIKE &#39;{$search_word}&#39;
							-- カスタムフィールド「my_custom_key01」と「my_custom_key02」
							AND meta_key IN ( &#39;my_custom_key01&#39;, &#39;my_custom_key02&#39; )
					)
				) &quot;;
			}
		}
	}
	return $search;
}
add_filter( &#39;posts_search&#39;,&#39;custom_search&#39;, 10, 2 );</code></pre></div>



<div class="wp-block-group is-style-big_icon_good"><div class="wp-block-group__inner-container">
<p>「特定のカスタムフィールド」を条件にするときは、以下のように<strong>配列形式でカスタムフィールドの「キー名」を指定</strong>します。</p>



<p class="is-style-dent_box">meta_key IN ( &#8216;<strong>my_custom_key01</strong>&#8216;, &#8216;<strong>my_custom_key02</strong>&#8216; )</p>



<p class="has-text-align-center is-style-balloon_box2">プラグイン「Advanced Custom Fields」を使用している場合は<br><strong>フィールド名</strong>が「<strong>キー名</strong>」に該当します。</p>


<div class="wp-block-image size_xs is-style-shadow">
<figure class="aligncenter size-full"><img decoding="async" width="739" height="496" src="https://kekenta-it-blog.com/wp-content/uploads/2024/07/meta_key_for_acf.jpg" alt="ACFを使用する場合のキー名" class="wp-image-9657" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/07/meta_key_for_acf.jpg 739w, https://kekenta-it-blog.com/wp-content/uploads/2024/07/meta_key_for_acf-300x201.jpg 300w" sizes="(max-width: 739px) 100vw, 739px" /><figcaption class="wp-element-caption">ACFを使用する場合のキー名</figcaption></figure>
</div></div></div>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">まとめ</h2>



<p>以上が<strong><span class="swl-marker mark_yellow">WordPressの検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する方法</span></strong>でした。</p>



<p>ご覧いただくとお分かりのように、デフォルトの検索機能をカスタマイズするためには<strong>WordPressのデータベース構造を理解した上でSQL文を組み立てる</strong>必要があります。</p>



<p>逆に言えば、SQLをある程度知っていてWordPressのデータベース構造も理解できれば<strong>検索機能の複雑なカスタマイズも可能になる</strong>ということでもあります。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/真顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/真顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -thinking -border-on"><div class="c-balloon__text">
<p>（そこのハードルがそれなりに高いのではないかと思いますが……）</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>僕も最初はWordPressのデータベースとphpMyAdmin経由でにらめっこしたり、あれこれ試行錯誤することで少しずつ理解を進めることができました。</p>



<p>この記事が読者の方にとっての学習のきっかけや、その一助になったなら幸いです。</p>



<p>それでは、最後までご覧いただきありがとうございました！</p>



<p class="is-style-balloon_box2">今回参考になった書籍</p>


<div id="rinkerid9666" class="yyi-rinker-contents   yyi-rinker-postid-9666 yyi-rinker-no-item">
	<div class="yyi-rinker-box">
		<div class="yyi-rinker-image"></div>
		<div class="yyi-rinker-info">
			<div class="yyi-rinker-title">
								サイトの拡張性を飛躍的に高める WordPressプラグイン開発のバイブル[ 宮内 隆行 ]							</div>

			<div class="yyi-rinker-detail">
											</div>
						<ul class="yyi-rinker-links">
																	<li class="amazonlink">
						<a href="https://www.amazon.co.jp/%E3%82%B5%E3%82%A4%E3%83%88%E3%81%AE%E6%8B%A1%E5%BC%B5%E6%80%A7%E3%82%92%E9%A3%9B%E8%BA%8D%E7%9A%84%E3%81%AB%E9%AB%98%E3%82%81%E3%82%8B-WordPress%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E9%96%8B%E7%99%BA%E3%81%AE%E3%83%90%E3%82%A4%E3%83%96%E3%83%AB-%E5%AE%AE%E5%86%85-%E9%9A%86%E8%A1%8C/dp/4797373520?dib=eyJ2IjoiMSJ9.YRg8NA4RY7Ahl1udiZdX2gqCH1sr0xMsjjBYG_2zrdiI3hzGlT8-0aPBPrSJOmzEs89jh-jFBk_pNRdwpKCmDBMzhOBkqiSDSi38qmjJY_HfcFDgjL9b-lQmZdPwT4x_11X9jFraYNweHbE1r7-3BmEjxY4tgmtlnIAjuu-_sX9k51AiJAw_CKiFo1clMJ_t0gXaSqYudoMYcn1cTh-oL-4eLzJclN6q_Af7es4RLw7HuXkYfVb30rOmXsTrjznel0VVpNYR-SbRXIblcdnUSVf4yMZvVKRaFhc4YR47zM8.KC4w7v20VWOsbVdh4f09xmoHvj8WQH3MJ1xLSaOvgsA&amp;dib_tag=se&amp;keywords=WordPress+%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3&amp;qid=1723549026&amp;sr=8-2&amp;linkCode=ll1&amp;tag=kekenta03am0b-22&amp;linkId=c85a6af04e43ad163d6468378b6c1d6c&amp;language=ja_JP&amp;ref_=as_li_ss_tl&amp;tag=kekenta03am0b-22&amp;index=blended&amp;linkCode=ure&amp;creative=6339" rel="nofollow" class="yyi-rinker-link yyi-rinker-tracking"  data-click-tracking="amazon 9666 サイトの拡張性を飛躍的に高める WordPressプラグイン開発のバイブル[ 宮内 隆行 ]"  data-vars-amp-click-id="amazon 9666 サイトの拡張性を飛躍的に高める WordPressプラグイン開発のバイブル[ 宮内 隆行 ]">Amazon</a>					</li>
													<li class="rakutenlink">
						<a href="https://hb.afl.rakuten.co.jp/hgc/3ace225e.aaf54072.3ace225f.2cf27f19/Rinker_o_20240730170413?pc=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FWordPress%25E3%2580%2580%25E3%2583%2597%25E3%2583%25A9%25E3%2582%25B0%25E3%2582%25A4%25E3%2583%25B3%2F%3Ff%3D1%26grp%3Dproduct&amp;m=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FWordPress%25E3%2580%2580%25E3%2583%2597%25E3%2583%25A9%25E3%2582%25B0%25E3%2582%25A4%25E3%2583%25B3%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow" class="yyi-rinker-link yyi-rinker-tracking"  data-click-tracking="rakuten 9666 サイトの拡張性を飛躍的に高める WordPressプラグイン開発のバイブル[ 宮内 隆行 ]"  data-vars-amp-click-id="rakuten 9666 サイトの拡張性を飛躍的に高める WordPressプラグイン開発のバイブル[ 宮内 隆行 ]">楽天市場</a>					</li>
													<li class="yahoolink">
											</li>
				                											</ul>
					</div>
	</div>
	</div>

<div class="p-blogParts post_content" data-partsID="10168">
<p class="is-style-balloon_box"><strong>検索機能の関連記事</strong></p>


<div class="p-postListWrap"><ul class="p-postList -type-simple"><li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-exc-page/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-15" aria-label="公開日">2024-08-15</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索結果から固定ページを除外する方法【コピペで簡単！】</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom-ssp/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-07" aria-label="公開日">2024-08-07</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-02" aria-label="公開日">2024-08-02</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-create-search/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-06-26" aria-label="公開日">2024-06-26</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能と検索結果ページを作成する方法</h2>		</div>
	</a>
</li>
</ul></div></div>]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-search-condition-custom/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【WordPress】検索機能と検索結果ページを作成する方法</title>
		<link>https://kekenta-it-blog.com/wp-create-search/</link>
					<comments>https://kekenta-it-blog.com/wp-create-search/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Wed, 26 Jun 2024 08:11:24 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[検索機能]]></category>
		<category><![CDATA[検索結果]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=8483</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/eye-catch__wp-create-search__8483-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>このようなお悩みをお持ちの方に向けて、この記事では WordPressのオリジナルテーマで検索機能と検索結果ページを作成する方法 をご紹介します。 一見すると難しそうに思うかもしれませんが、WordPressではシンプル [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/eye-catch__wp-create-search__8483-1024x576.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>WordPressのオリジナルテーマで「検索機能」ってどうやったら実装できるの……？</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>このようなお悩みをお持ちの方に向けて、この記事では</p>



<p class="has-text-align-center is-style-big_kakko_box"><strong>WordPressのオリジナルテーマで<br>検索機能と検索結果ページを作成する方法</strong></p>



<p>をご紹介します。</p>



<p>一見すると難しそうに思うかもしれませんが、WordPressではシンプルな検索機能であればプラグインを使用しなくても簡単に実装することが可能です。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>この記事の手順通りに作業を進めれば簡単に実装できますので、ぜひ最後までご覧下さい！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<div class="swell-block-capbox cap_box is-style-shadow"><div class="cap_box_ttl"><span><span data-icon="LsLightbulb" data-id="0" style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJNMzIgNDYuNUgxNmMtMS4xIDAtMi0uOS0yLTJzLjktMiAyLTJoMTZjMS4xIDAgMiAuOSAyIDJzLS45IDItMiAyek00MS43IDE1LjlDNDEuMyAxMyA0MCAxMC4zIDM4LjIgOCAzNC41IDMuMiAyOSAuOCAyMy4xIDEgMTQgMS40IDYuNSA4LjkgNiAxOGMtLjMgNiAyLjQgMTEuNyA3LjIgMTUuNC41LjQuOC45LjggMS41djEuNmMwIDIuMiAxLjggNCA0IDRoMTJjMi4yIDAgNC0xLjggNC00VjM1YzAtLjYuMy0xLjIuOS0xLjcgNS4zLTQgOC0xMC42IDYuOC0xNy40em0tNy4xIDEuN2gtLjNjLS43IDAtMS4zLS41LTEuNS0xLjItLjctMy4yLTMuMi01LjctNi40LTYuMy0uOC0uMS0xLjQtLjktMS4yLTEuN3MuOS0xLjQgMS43LTEuMmM0LjQuOCA4IDQuMiA4LjkgOC42LjEuOC0uNCAxLjYtMS4yIDEuOHoiPjwvcGF0aD48L3N2Zz4=)" aria-hidden="true" class="swl-inline-icon"> </span><strong> この記事で作成する検索機能のポイント</strong></span></div><div class="cap_box_content">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li>検索対象は<strong>タイトル</strong>と<strong>本文</strong>（それ以外の部分を検索対象に含めたい場合はプラグイン等でのカスタマイズが必要）</li>



<li>半角スペースで区切れば複数キーワード検索が可能（全角スペースは不可）</li>
</ul>
</div></div>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-subloop-wq/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】WP_Query（サブループ）の使い方とパラメータ一覧を紹介</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2025/03/eye-catch__school-php-and-wp__14099-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/school-php-and-wp/">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</a>
						<span class="p-blogCard__excerpt">僕はこれまで独学でPHPを学習してきました。結論から言えば、それでもPHPを習得することはできました。 しかし、それに費やした累計学習期間は1年ほど。モチベーション&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">WordPressにおける検索機能実装の流れ</h2>



<p>WordPressで検索機能を実装する際は、大まかには以下のような流れをたどります。</p>



<div class="swell-block-capbox cap_box"><div class="cap_box_ttl"><span>WordPressにおける検索機能実装の流れ</span></div><div class="cap_box_content">
<ul class="wp-block-list is-style-num_circle -list-under-dashed">
<li>検索フォーム用のPHPファイル（searchform.php）を作成する</li>



<li>検索結果ページ用のPHPファイル（search.php）を作成する</li>



<li>①で作成した<strong>検索フォーム</strong>を任意の場所で呼び出す</li>
</ul>
</div></div>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>それでは各工程について順番にご説明していきます。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="is-style-icon_info">以降より掲載するディレクトリはローカル上でのものになりますが、実際にファイル配置する際にはご自身の環境（本番サーバー）で作業をお進めください。</p>



<h3 class="wp-block-heading">【手順①】検索フォーム用のPHPファイル（searchform.php）を作成する</h3>



<div class="swell-block-step" data-num-style="circle">
<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l">テーマディレクトリ直下に検索フォーム用のPHPファイル（searchform.php）を作成する</div><div class="swell-block-step__body">
<p class="is-style-bg_stripe">まずは使用中のテーマディレクトリ直下に検索フォーム用のPHPファイルを作成します。</p>



<p class="has-text-align-center is-style-balloon_box2"><strong><strong>searchform</strong>.php</strong>を<strong>テーマディレクトリ直下</strong>に設置</p>


<div class="wp-block-image is-style-shadow size_s">
<figure class="aligncenter size-full"><img decoding="async" width="620" height="518" src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-58.png" alt="searchform.phpを作成" class="wp-image-8708" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-58.png 620w, https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-58-300x251.png 300w" sizes="(max-width: 620px) 100vw, 620px" /><figcaption class="wp-element-caption">searchform.phpを作成</figcaption></figure>
</div></div></div>



<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l">作成したファイルに検索フォームのソースコードを記述</div><div class="swell-block-step__body">
<p class="is-style-bg_stripe">続いて、作成したファイルに検索フォームのソースコードを記述します。</p>



<p class="has-text-align-center is-style-balloon_box2"><strong><strong>searchform</strong>.php</strong>に記述</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;form action=&quot;&lt;?php echo esc_url(home_url(&#39;/&#39;)); ?&gt;&quot; method=&quot;get&quot; class=&quot;my_searchform&quot;&gt;
	&lt;input name=&quot;s&quot; id=&quot;s&quot; type=&quot;text&quot; value=&quot;&lt;?php the_search_query(); ?&gt;&quot; placeholder=&quot;検索キーワードを入力して下さい&quot; /&gt;
	&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;検索&quot; /&gt;
&lt;/form&gt;</code></pre></div>



<div class="swell-block-capbox cap_box"><div class="cap_box_ttl"><span><strong><strong>searchform</strong>.phpのポイント</strong></span></div><div class="cap_box_content">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li>&lt;form&gt;タグの<strong>action属性</strong>には「自分のサイトのトップページURL」を指定する</li>



<li>&lt;form&gt;タグの<strong>method属性</strong>は「get」にする</li>



<li>ひとつ目の&lt;input&gt;タグの<strong>name属性</strong>は「s」にする</li>



<li>ひとつ目の&lt;input&gt;タグの<strong>value属性</strong>には「the_search_query();」を設定し、検索結果ページで検索キーワードを表示できるようにする</li>



<li>ふたつ目の&lt;input&gt;タグの<strong>type属性</strong>は「submit」にする</li>
</ul>
</div></div>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>WordPressではたったこれだけのソースコードで検索機能が動くようになります！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div></div></div>
</div>



<h3 class="wp-block-heading">【手順②】検索結果ページ用のPHPファイル（search.php）を作成する</h3>



<p class="is-style-bg_stripe">【手順①】で検索機能自体は動くようになりましたが、これでは検索結果が表示されないため、今度は<strong>検索結果ページ用のファイル</strong>を準備していきます。</p>



<div class="swell-block-step" data-num-style="circle">
<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l">テーマディレクトリ直下に検索結果表示用のPHPファイル（search.php）を作成する</div><div class="swell-block-step__body">
<p class="is-style-bg_stripe">まずは使用中のテーマディレクトリ直下に検索結果表示用のPHPファイルを作成します。</p>



<p class="has-text-align-center is-style-balloon_box2"><strong><strong>search</strong>.php</strong>を<strong>テーマディレクトリ直下</strong>に設置</p>


<div class="wp-block-image is-style-shadow size_s">
<figure class="aligncenter size-full"><img decoding="async" width="620" height="518" src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-59.png" alt="search.phpを作成" class="wp-image-8716" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-59.png 620w, https://kekenta-it-blog.com/wp-content/uploads/2024/06/image-59-300x251.png 300w" sizes="(max-width: 620px) 100vw, 620px" /><figcaption class="wp-element-caption">search.phpを作成</figcaption></figure>
</div></div></div>



<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l">作成したファイルに検索結果表示用のソースコードを記述</div><div class="swell-block-step__body">
<p class="is-style-bg_stripe">続いて、作成したファイルに検索結果表示用のソースコードを記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;div&gt;
    &lt;p&gt;&lt;?php echo &#39;「&#39; . get_search_query() . &#39;」の検索結果：&#39; . $wp_query-&gt;found_posts . &#39; 件の記事が該当しました。&#39;;?&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;main&gt;
    // メインループを回して検索結果として取得できた記事を出力する
    &lt;?php if ( have_posts() ): ?&gt;
        &lt;?php while ( have_posts() ) : the_post();?&gt;
        &lt;div&gt;
          &lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
          &lt;?php the_excerpt(); // 記事の抜粋?&gt;
          &lt;div&gt;
            &lt;p&gt;投稿日：&lt;?php echo get_the_date(); ?&gt;投稿時間：&lt;?php the_time(); ?&gt;カテゴリー：&lt;?php the_category(&quot; , &quot;); // 「,」区切りでカテゴリーを出力?&gt;&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
       &lt;?php endwhile; ?&gt;

       &lt;?php else: ?&gt;
           &lt;p&gt;該当する記事はありませんでした。&lt;/p&gt;
    &lt;?php endif; ?&gt;
    &lt;/main&gt;
&lt;/div&gt;</code></pre></div>



<div class="swell-block-capbox cap_box"><div class="cap_box_ttl"><span><strong><strong>search</strong>.phpのポイント</strong></span></div><div class="cap_box_content">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><strong>get_search_query()</strong>（ソースコード2行目）で「入力された検索キーワード」を取得</li>



<li><strong>$wp_query-&gt;found_posts</strong>（ソースコード2行目）で「見つかった検索結果件数」を取得</li>



<li><strong>メインループ</strong>を回して「取得できた検索結果の記事」を1件ずつ出力</li>



<li>取得した記事が無ければ「該当する記事はありませんでした。」のテキストを出力（ソースコード19～21行目）</li>
</ul>
</div></div>
</div></div>
</div>



<h3 class="wp-block-heading">【手順③】①で作成した<strong>検索フォーム</strong>を任意の場所で呼び出す</h3>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>最後に、作成した検索フォームを任意の場所で呼び出します。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>呼び出し方はいたって簡単で、以下のソースコードを検索フォームを出力したい場所に記述するだけです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;?php get_search_form(); ?&gt;</code></pre></div>



<p class="is-style-big_icon_check">これはget_header()やget_footer()のような<strong>インクルードタグの１種</strong>です。<br><strong>get_search_form()</strong>によって【手順①】で作成したsearchform.phpが自動的に呼び出され、その中身である検索フォーム部分が表示されます。</p>



<h2 class="wp-block-heading">最後にCSSで自分好みの見た目に調整すれば完成！</h2>



<p>以上が<strong>WordPressで検索機能を実装する方法</strong>でした。</p>



<p>検索フォームや検索結果ページは、<strong><span class="swl-marker mark_yellow">HTMLやCSSを使用してご自身が好きな見た目に調整可能</span></strong>です。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p><strong>検索フォームの一部の属性</strong>だけは決められた値を設定する必要がありますが、class名やid名などは任意のものを設定可能です。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>また、検索結果ページに出力する内容も、基本的には「メインループで１件ずつ出力する」という部分を抑えていれば自由にカスタマイズできます。</p>



<p>この記事のソースコードをベースに、ぜひご自身の状況に適したカスタマイズを行ってみて下さい。</p>



<p>それでは最後までご覧いただきありがとうございました。</p>



<p>当ブログではWordPressやWeb制作、PHPの情報を発信しています。<br>ご興味のある方は他の記事もご覧いただけると嬉しいです。</p>


<div class="p-blogParts post_content" data-partsID="10168">
<p class="is-style-balloon_box"><strong>検索機能の関連記事</strong></p>


<div class="p-postListWrap"><ul class="p-postList -type-simple"><li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-exc-page/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-15" aria-label="公開日">2024-08-15</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索結果から固定ページを除外する方法【コピペで簡単！】</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom-ssp/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-07" aria-label="公開日">2024-08-07</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にSEO SIMPLE PACKの設定内容を追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-search-condition-custom/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-08-02" aria-label="公開日">2024-08-02</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能の条件にタグ・カテゴリー・カスタムフィールドを追加する</h2>		</div>
	</a>
</li>
<li class="p-postList__item">
	<a href="https://kekenta-it-blog.com/wp-create-search/" class="p-postList__link">
		<div class="p-postList__body">
			<div class="p-postList__meta">
				<div class="p-postList__times c-postTimes u-thin">
	<time class="c-postTimes__posted icon-posted" datetime="2024-06-26" aria-label="公開日">2024-06-26</time><time class="c-postTimes__modified icon-modified" datetime="2025-03-18" aria-label="更新日">2025-03-18</time></div>
		<span class="p-postList__cat u-thin icon-folder" data-cat-id="74">WordPress</span>
				</div>
			<h2 class="p-postList__title">【WordPress】検索機能と検索結果ページを作成する方法</h2>		</div>
	</a>
</li>
</ul></div></div>]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-create-search/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
