A full, working-code style answer is a bit out of scope here, but here are some suggestions for your two questions:
-
Custom fields are saved as postmeta. So you’ll want to set up a simple form with one text input and GET method. In your PHP to process the form, check whether your $_GET variable is set. If not, display the empty form. If so, use a WP_Query to find all posts with the given parameters. Here’s an excellent answer that shows how to do a greater-than-or-equal-to comparison on postmeta.
-
The code from your second link only works within the Loop. The main query has already run by the time this code executes, so it appears to be meant to run only on an Archive which would already have a number of posts fetched from the database.
Related Posts:
- ajax category filter
- Sorting Posts by custom field
- Refine/Filter WP_Query Posts with jQuery or Ajax
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- WP Group posts by year(desc) > month(desc) > date(asc)
- Change AJAX filter from POST to GET for URL Parameters
- Retrieve select tag custom values from array and display them in current page with wp_query?
- meta_query weird behaviour, static int will work, but not user data
- How to add a “base” filter for all posts visible to visitors on the site?
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Order 2 meta_queries differently in WP_Query?
- Sort posts on custom field AND after that sort on date?
- Wrap group of wp query posts to parent div by date/year
- Sorting posts by meta values: 2 different orders
- query_posts with sorting on a custom datestamp
- query post based on comparison
- Adding arguments to WooCommerce Product Loop using AJAX
- WP_Query – order with usort by custom meta
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Filter posts in category archive page by year using a dropdown
- Extend product search with meta in WooCommerce
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Ajax WP_Query reutrns no results on author.php
- how to make members list directory through wordpress post custom meta key.
- Display filtered results into custom page
- Order by empty custom field
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Query posts without meta preload
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- Large AND OR query timing out
- Applying posts_clauses filter to specific queries only
- Help ordering Post loop by two meta values
- Add class to first post in custom loop using post_class filter
- WP_Query with different postmeta filter for each categories
- meta_value_num not ordering all items
- Slow WP_Query with ‘OR’ on meta_query
- Add posts to WP Query object
- Categorising search results based on Custom Fields
- Current post in AJAX call is always zero
- How to sort a custom wordpress query by combination of meta values?
- Gallery shortcode numerical sorting
- Filter wordpress post categories with jquery/ajax and pagination?
- Query all posts if multiple meta key don’t exist
- meta_compare not comparing whole integer
- How to alter local query, not main query [duplicate]
- How to filter a query by date in a shortcode?
- How can I allow sticky posts but cap the query to 1 post?
- Redirect to another page using contact form 7? [closed]
- how to access query string in wordpress?
- Does wp track views for posts?
- Sort WordPress Posts Meta value by Week not Day
- Search posts missing a particular custom field
- Ajax future single post query doesn’t work when NOT logged in
- wp_query to print posts if have X custom field value
- how update data through ajax and jquery
- Filter Custom Taxonomy Posts
- wp_query get data from advanced custom field in wordpress
- Why is WP_Query not displaying expected data?
- How to compare a date in custom field with today’s date in custom WP_Query?
- Include posts from some categories while excluding from others
- Changing the default wp_search_stopwords
- How to order WP_Query to group results?
- WP_Query Meta_key is text value and need to sort as numeric not working
- Filter post query to only show direct children of category
- Error with function in functions.php?
- filter wp_query result with custom field values
- I am having problem sorting custom post type using WP_Query
- Order post type by sum of two custom fields
- Select custom posts by meta_value and sort by a different meta value
- Use Ajax To filter posts?
- Is it possible to add an argument to a custom function added to a filter hook?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- WP ForLoop to compare meta information of posts to determine what post to display
- Using post_where filter only on main query NOT sidebard new WP_Query
- Filtering posts by archive showing all years
- WP_QUERY with group by with custom fields
- Loading two different AJAX requests on two different pages
- How to order posts on each different category?
- AJAX Breaking Offset Argument In WP Query
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- Apply filters to main query instead of creating new one?
- Intiger meta value with ‘>=’ returns posts with lower value
- WP_Query – How to get all posts of specific days of week by custom field date?
- Display posts with specific value first in query
- get_posts custom field
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- wp_query posts with custom fields number smaller than
- WP_Query offset is returning post from prevois loop
- Sorting search results with custom dropdown
- Sort posts by clicks on download button
- Posts query according to meta box date
- create metabox to activate slider
- Multiple wp_query on archive page
- Query posts using less than
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- Order WP_Query results by meta key value in custom query