Add a custom variable to query page object

I updated my question with a partial answer to this problem. By adding an underscore ‘_’ before the name of the meta field it allows you to add meta data without it creating an editable custom field on the page edit screen. update_post_meta( get_queried_object()->ID, ‘_term_id’, $meta_term_id);

WordPress Query posts that have title > another title

You can use get_page_by_title to match the title of the required post. $post_name = get_page_by_title( ‘Post Title’ ); $vars = array( ‘name’ => $post_name, ‘paged’ => $page, ‘posts_per_page’ => intval($posts), ‘order’ => ‘asc’, ‘offset’ => ($offset ? $offset : ”), ‘orderby’ => ‘title’ );

Return on a quest all these meta_value

You need to use a meta query: if ( isset( $_REQUEST[‘src’] ) ) { $query = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( ), ); if ( isset( $_REQUEST[‘srcbusiness’] ) ) { $query[‘category_name’] = wp_unslash( $_REQUEST[‘srcbusiness’] ); } $fields = array( ‘srctype’, ‘srcprice’, ‘srccity’, ‘srcdistrict’, ); foreach ( $fields as $field ) { if ( … Read more

Get results from the main wp_query

It looks like you’re calling preparePDF( $wp_query ) inside your callback, but $wp_query isn’t defined and the global $wp_query shouldn’t be accessible there without global $wp_query. Try instead preparePDF( $query ) and use wp_reset_postsdata() to restore the global $post object. Another important thing is that you must run your preparePDF() function after WP_Query has fetched … Read more

Display Count of posts

You should be able to get that number from the same $wp_query object: global $wp_query; $num_pages = $wp_query->found_posts; $num_pages will contain the total count that matches your category (or whatever other criteria you’re using). If you’re just looking to get a string you can display, this modified version of the function will work. function get_post_number() … Read more