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
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Can wp_query return posts meta in a single request?
- compare meta_query in get_posts arguments
- Filter WP_Query for posts having a certain meta-value
- Function in array as arguments for WP_Query
- WP_Query to show post from a category OR custom field
- Getting attachments by meta value
- Sorting a query by custom field date
- Changing Posts Per Page and offset with pre_get_posts
- meta_query where value is equal to given value
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- WordPress altering my custom query, How to fix it?
- Using AJAX to return search form results
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Order by meta_key in custom post type doesn’t affect the query
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- Filtering posts by custom field value not working
- Order Posts by meta value AND published date
- Use ‘parse_query’ filter to show posts that from multiple criteria
- Using apply_filters(‘the_content’, $custom_query->post_content) alters output
- Modifying the Search Results
- wp_query add arguments using array_push if variable met
- Group WP_Query by meta_key date
- How To Fix WP Query Returns Results But Shouldn’t?
- How to Filter Posts by Custom Fields?
- Order by title without taking into account ‘the’
- Fetch Record based on meta key dates
- Orderby is working with one query but not with other
- how to handle multiple ajax wordpress queries?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- meta_value_num not ordering all items
- Redirect to another page using contact form 7? [closed]
- Sort WordPress Posts Meta value by Week not Day
- wp_query get data from advanced custom field in wordpress
- Include posts from some categories while excluding from others
- WP_Query Meta_key is text value and need to sort as numeric not working
- filter wp_query result with custom field values
- Filtering posts by archive showing all years
- Apply filters to main query instead of creating new one?
- WP_Query – How to get all posts of specific days of week by custom field date?
- Querying a large number of posts including their custom fields data
- WP_query is not returning the expected result
- I need to run a AJAX Fuction from within a WP_Query but only works on first item
- How to filter a static post page with ajax and $wp_query
- Custom post type – filter content by custom meta box content
- orderby ignored by wp_query
- Filter or order based on custom field
- Query multiple post types, but different order for each
- Order by the first array within a meta_query
- Query ACF relationship field – Comparator IN – Value array
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- display ACF repater field in archive page
- Filter admin ajax data by url query
- Comparing Meta Field date in WPQuery using Meta_Query?
- WP_Query, ACF field and array
- Load WP Query with Ajax
- using custom meta user data to run queries in WordPress
- WP Query filters active on wrong query
- Insert wp_query after the_content with plugin (filter the_content won’t work)
- Gather same custom field values in one value in a select tag with wp_query
- Is instantiating WP_Query not possible within an admin Ajax call?
- WordPress conflict with multiple load more posts functions on click
- Meta key in wp_query bug?
- Track write actions to the database
- Fetch only categorized posts
- Using custom field as ‘orderby’ value causing post grouping by publish date
- WP_Query for liked posts is showing all posts if none are liked
- Declare inline background image in functions.php
- Order Custom Field by Price
- Sorting Posts with meta value not working
- Fire query on ajax post url page
- Sort posts after filtering them through multiple taxonomies
- Get posts by meta value except one post [closed]
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function
- Best performance for use Custom Field in WP