Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:43:52+00:00 2026-05-26T19:43:52+00:00

I have a listing of custom post types and I’m trying to implement a

  • 0

I have a listing of custom post types and I’m trying to implement a search form over it. The search form will simply push url queries that will be caught by the same page and depending on these queries (such as name=”..”, order=”..”, etc.), the list of custom post types will represent these characteristics.

I’m especially stuck with implementing the arguments for WP_Query that will allow me to search through the meta data for each custom post type. Here is the structure of my $args string (as called by print_r – this will not display the exact syntax i’ve used, as it’s mixed with quite abit of logic, but this gives a good idea of how my arguments are interpreted):

[post_type] => obituary
[post_per_page] => 25
[meta_query] => Array
    (
        [relation] => OR
        [0] => Array
            (
                [meta_key] => last_name
                [meta_value] => Green
            )

        [1] => Array
            (
                [meta_key] => first_name
                [meta_value] => Green
            )

    )

If i remove key array[meta_query][0] (so the array defining the value to look as last_name (hence only looking under one meta data key), then the query will work OK. I thought of adding the relation key and value OR to be able to find the meta_value is either last_name OR first_name meta keys. However, this doesn’t seem to work, the query still returns the full list of custom post types.

As I am new to this, is there anything flagrant I’m missing? I’ve looked around through the docs I could find and this, imo, should work.

What are your thoughts?

Edit: A correction to the above: search under only one meta_key will only work if this is defined outside the meta_query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:43:53+00:00Added an answer on May 26, 2026 at 7:43 pm

    Figured it out. The right structure is as follows:

    (
        [post_type] => obituary
        [post_per_page] => 25
        [meta_query] => Array
            (
                [relation] => OR
                [0] => Array
                    (
                        [key] => last_name
                        [value] => Green
                        [compare] => LIKE
                    )
    
                [1] => Array
                    (
                        [mkey] => first_name
                        [value] => Green
                        [compare] => LIKE
                    )
    
            )
    
    )
    

    The main difference is that the meta_key and meta_value are called key and value when within the meta_query array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display results of a custom post type on my main
I have created my custom field type for listing available users in to Dropdownlist.
I have listing pages that take a page argument on the url like the
I have 100 property listings as wordpress posts and each post has two custom
I have the following custom query: @initial_matches = Listing.find_by_sql([SELECT * FROM listings WHERE industry
i have a custom list view. in that i am listing out images of
I have several pages listing search results, for each result I would like to
I have a fairly complicated ViewModel associated with a product listing form, which has
I have a listing in an UpdatePanel I have some filters for that list
Imagine the scenario you have a listing page that is a concatenation of multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.