How to create a dynamic page based on form data with a plugin?

Something like this should work, though I’m not sure how meta, title, etc.. will behave, you’ll want to test everything thoroughly! function my_template_redirect() { global $wp; $qvs = $wp->query_vars; if (array_key_exists( ‘laundry’, $qvs && $qvs[‘laundry’] == ‘thank-you’ ) { global $wp_query; $wp_query->set( ‘is_404’, false ); // … now what? $post = new stdClass(); $post->ID= -99; … Read more

How to pass custom parameter to WP_Query for filtering in pre_get_posts

You can access query variables (including custom ones) via the WP_Query::get() method. For example: $my_query = new WP_Query( array( … ‘wpse105219_custom_var’ => ‘foobar’, … ) ); To ‘catch’ this at pre_get_posts: add_action( ‘pre_get_posts’, ‘wpse105219_pre_get_posts’, 10 ); function wpse105219_pre_get_posts( $query ){ if( $query->get( ‘wpse105219_custom_var’ ) == ‘foobar’ ){ //Alter $query } }

Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy

Something like this should help: <?php $post_type=”animals”; $tax = ‘vertebrate’; $tax_terms = get_terms($tax); if ( $tax_terms ) { foreach ($tax_terms as $tax_term) { $args = array( ‘post_type’ => $post_type, “$tax” => $tax_term->slug, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘caller_get_posts’ => 1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); // $my_query = null; <- REMOVE THIS, … Read more

WP API to fetch all the media/posts records if count is more than 100

Add a page number query to your request URL, and continue querying next page numbers until you get an empty result: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=100&page=2 Mark’s suggestion to consider requesting less than 100 per page may be a good one. So for example you may want to do your query this way: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=25&page=3 Note also that (for me … Read more

WP_Query on different site in a multisite setup

Alternative option could be using the Rest API: Example (post): Search for Jane Doe in posts: https://example.com/staffsite/wp-json/wp/v2/posts/?search=jane+doe Example (custom post types): If the public and searchable custom post type (e.g. staff) has show_in_rest set to true then we can search for Jane Doe in staff posts: https://example.com/staffsite/wp-json/wp/v2/staff/?search=jane+doe ps: Somewhat related, if you want to create … Read more

Using Cookie Data For WP_Query Loop

You need to explode the comma separated string to get the array of IDs. Follow the below code. $cookie_array = $_COOKIE[“your-results”]; // Test output echo $cookie_array; $cookie_array = array_map( ‘absint’, (array) explode(‘,’, $cookie_array) ); $sug_args = array( ‘post_type’ => ‘product’, ‘post__in’ => $cookie_array, ); $sug_query = new WP_query ($sug_args); if( $sug_query->have_posts() ) : while( $sug_query->have_posts() … Read more