Home CMS Tutorial WordPress How to limit search results for specific post types in WordPress

How to limit search results for specific post types in WordPress

Apr 20, 2025 am 06:06 AM
wordpress 2025

How to limit search results for specific post types in WordPress

Have you ever wondered how to limit search results to specific post types? This is not very difficult. We have shown you how to disable search functionality in WordPress by modifying the functions.php file. Now we are going to do the same thing, except filtering our search results.

Open your functions.php file and add the following code:

 functionsearchfilter($query) { if($query->is_search && !is_admin() ) { $query->set('post_type',array('post','page')); } return$query;}add_filter('pre_get_posts','searchfilter');
Copy after login

Depend on

Use it with one click in WordPress

Please note this line

 $query->set('post_type',array('post','page'));
Copy after login

Depend on

Use it with one click in WordPress

You can filter search results by changing the values ​​in array variables. Now it is set to show posts and pages, but you can modify it to show whatever you want.

The above is the detailed content of How to limit search results for specific post types in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Which three major U.S. stock index futures rise Which three major U.S. stock index futures rise Apr 21, 2025 am 07:48 AM

On April 8, 2025, the three major U.S. stock index futures all rose. The specific situation is: 1. Dow futures rose 2%; 2. S&P 500 futures rose 1.78%; 3. Nasdaq futures rose 1.75%.

Top 11 list of Bitcoin Exchange Rate Conversion Global (Updated in 2025) Top 11 list of Bitcoin Exchange Rate Conversion Global (Updated in 2025) Apr 21, 2025 am 11:27 AM

The exchange rate of Bitcoin to currencies of various countries is as follows: 1. USD: at 7:20 on April 9, the exchange rate is 10,152.53. 2. Domestic: at 2:2 on April 9, 1 Bitcoin = 149,688.2954 yuan. 3. Swedish Krona: At 12:30 on April 9, the exchange rate was 758,541.05.

Litecoin (LTC) price drops sharply to $65 Litecoin (LTC) price drops sharply to $65 Apr 21, 2025 pm 06:15 PM

Litecoin (LTC) price plummeted to $65 in early April, down nearly 7.5% in a week, echoing the plunge in the wider cryptocurrency market. The market crash caused billions of dollars to evaporate market value, Bitcoin (BTC) fell below $75,000, and altcoins generally fell. Macro factors such as rising U.S. Treasury yields and expected interest rates appear to intensify risk aversion in global markets. In addition, the large outflow of funds from Bitcoin spot ETFs further hits the confidence of retail investors and institutional investors. Against this backdrop, Litecoin is once again facing its long-term resistance level - the 200-week exponential moving average (EMA). The EMA had suppressed LTC prices in July 2023, when the price was close to $88. Historically, LTC and the

Binance's big move: The margin collateral ratio of multi-currency combinations will be adjusted in April Binance's big move: The margin collateral ratio of multi-currency combinations will be adjusted in April Apr 21, 2025 am 11:36 AM

Binance made several adjustments to the margin collateral ratio of multi-currency combinations in April 2025. 1. Adjustment on April 4: In the multi-asset margin mode, FLOW and COMP have dropped from 80% to 70%, 1INCH has dropped from 70% to 65%, HOT and RVN have dropped from 70% to 60%, IOTX has dropped from 70% to 55%; in the unified account mode, CRV and UNI have dropped from 85% to 80%, ALGO has dropped from 85% to 75%, KSM has dropped from 80% to 70%, XTZ has dropped from 75% to 60%, and XEC has dropped from 70% to 55%. 2. Adjustment on April 11: In the combination margin mode, ICP dropped from 80% to 70%, SNX dropped from 80% to 65%, and MANA dropped from 75% to 6

What to do if the USDT transfer address is incorrect? Guide for beginners What to do if the USDT transfer address is incorrect? Guide for beginners Apr 21, 2025 pm 12:12 PM

After the USDT transfer address is incorrect, first confirm that the transfer has occurred, and then take measures according to the error type. 1. Confirm the transfer: view the transaction history, obtain and query the transaction hash value on the blockchain browser. 2. Take measures: If the address does not exist, wait for the funds to be returned or contact customer service; if it is an invalid address, contact customer service and seek professional help; if it is transferred to someone else, try to contact the payee or seek legal help.

WorldCoin (WLD) price forecast 2025-2031: Will WLD reach USD 4 by 2031? WorldCoin (WLD) price forecast 2025-2031: Will WLD reach USD 4 by 2031? Apr 21, 2025 pm 02:42 PM

WorldCoin (WLD) stands out in the cryptocurrency market with its unique biometric verification and privacy protection mechanisms, attracting the attention of many investors. WLD has performed outstandingly among altcoins with its innovative technologies, especially in combination with OpenAI artificial intelligence technology. But how will the digital assets behave in the next few years? Let's predict the future price of WLD together. The 2025 WLD price forecast is expected to achieve significant growth in WLD in 2025. Market analysis shows that the average WLD price may reach $1.31, with a maximum of $1.36. However, in a bear market, the price may fall to around $0.55. This growth expectation is mainly due to WorldCoin2.

What does cross-chain transaction mean? What are the cross-chain transactions? What does cross-chain transaction mean? What are the cross-chain transactions? Apr 21, 2025 pm 11:39 PM

Exchanges that support cross-chain transactions: 1. Binance, 2. Uniswap, 3. SushiSwap, 4. Curve Finance, 5. Thorchain, 6. 1inch Exchange, 7. DLN Trade, these platforms support multi-chain asset transactions through various technologies.

Ranking of legal platform apps for virtual currency trading Ranking of legal platform apps for virtual currency trading Apr 21, 2025 am 09:27 AM

This article lists the ranking of APPs for legal platforms for virtual currency transactions, emphasizing that compliance is an important consideration for choosing a platform. The article recommends platforms such as Coinbase, Gemini, and Kraken, and reminds investors to study regulatory information and pay attention to security records when making choices. At the same time, the article emphasizes that virtual currency transactions are high-risk and investments should be cautious.

See all articles