Title: Custom Query
Last modified: March 4, 2018

---

# Custom Query

 *  Resolved [8edrich](https://wordpress.org/support/users/8edrich/)
 * (@8edrich)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/)
 * Hi all, I need some help with custom queries in TotalPress.
    How can I write 
   query to get only posts from an author ‘Bedrich’, where the custom field key 
   is ‘color’ and the custom field value is ‘blue’? Is this possible?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Theme Author [ThemeAWESOME](https://wordpress.org/support/users/tsquez/)
 * (@tsquez)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10036836)
 * Hi there,
    I am not sure I understand your question.
 * You want to get posts from a specific author using colors?
 *  Thread Starter [8edrich](https://wordpress.org/support/users/8edrich/)
 * (@8edrich)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10037203)
 * No, it was just an example…
    I want to get posts from a specific author, and 
   additionally where my custom field has a specific value. Like this:
 *     ```
       <?php
       $args = array(
           'author_name' => 'Bedrich',
           'post_type' => 'my-custom-post',
           'meta_key' => 'color',
           'meta_value' => 'blue');
       $the_query = new WP_Query( $args ); ?>
   
       <?php if ( $the_query->have_posts() ) : ?>
           <!-- the loop -->
           <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
               <h1 href="<?php the_permalink(); ?>"><?php the_title(); ?></h1>
               <?php the_content(); ?>
           <?php endwhile; ?>
       <?php endif; ?>
       ```
   
 * I dont know, how to implement such a query in TotalPress.
 *  Theme Author [ThemeAWESOME](https://wordpress.org/support/users/tsquez/)
 * (@tsquez)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10038242)
 * Hi there,
 * The way TotalPress is constructed is with hooks and filters. This allows the 
   end user to easily manipulate the way things work in the theme.
 * All of these hooks and filters are located in a file called `template-functions.
   php`. This file is located in `totalpres > assets > inc`. A few others are located
   in a file called `totalpress-extras.php`. This file is located in the same folder
   as mentioned before.
 * These hooks are called in different theme files. For example, the loop was turned
   into an action called `totalpress_main_loop` and this is called in the `archive.
   php` and `index.php` files.
 * Another reason why hooks and filters were used to create TotalPress is so that
   the end user did not have to copy any files into their child theme. All they 
   would have to use is the `functions.php` file to add their own hooks and filters
   and to overwrite any existing ones.
 * So basically what you need to do is or what I recommend you do create a child
   theme if you haven’t already done so. Then turn the query above into a `hook`,
   like this:
 *     ```
       // my specific author hook
       if ( ! function_exists('build_posts_from_specific_author')) :
       	function build_posts_from_specific_author() { 
       		$args = array(
       		    'author_name' => 'Bedrich',
       		    'post_type' => 'my-custom-post',
       		    'meta_key' => 'color',
       		    'meta_value' => 'blue');
       		$the_query = new WP_Query( $args ); ?>
       		<?php if ( $the_query->have_posts() ) : ?>
       		    <!-- the loop -->
       		    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       		        <h1 href="<?php the_permalink(); ?>"><?php the_title(); ?></h1>
       		        <?php the_content(); ?>
       		    <?php endwhile; ?>
       		<?php endif; ?>
       	<?php
       	}
       	add_action('posts_from_specific_author','build_posts_from_specific_author');
       endif;
       ```
   
 * Add the code to the child theme `functions.php` file and then call it where you
   need to like so:
 * `<?php do_action('posts_from_specific_author'); ?>`
 * I hope this helps, without knowing the actual specifics of how you’re going to
   display these posts or where you’re going to display these posts this about all
   I can offer.
 * If possible, you can contact me via ThemeAWESOME.com and I can help you get this
   sorted if you like.
 *  Thread Starter [8edrich](https://wordpress.org/support/users/8edrich/)
 * (@8edrich)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10042594)
 * Thank you very much!
    I will try it this way.
 * Bedrich
 *  Theme Author [ThemeAWESOME](https://wordpress.org/support/users/tsquez/)
 * (@tsquez)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10048578)
 * Awesome! Please let me know how it goes for you and if there is anything else
   I can assist you with.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom Query’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/totalpress/6.5.3.1/screenshot.
   png)
 * TotalPress
 * [Support Threads](https://wordpress.org/support/theme/totalpress/)
 * [Active Topics](https://wordpress.org/support/theme/totalpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/totalpress/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/totalpress/reviews/)

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * 5 replies
 * 2 participants
 * Last reply from: [ThemeAWESOME](https://wordpress.org/support/users/tsquez/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/custom-query-13/#post-10048578)
 * Status: resolved