query_vars category_name only display one catgory out of multiple categories

Inside get_posts() of WP_Query class, you will see this code block. /* * Ensure that ‘taxonomy’, ‘term’, ‘term_id’, ‘cat’, and * ‘category_name’ vars are set for backward compatibility. */ if ( ! empty( $this->tax_query->queried_terms ) ) { /* * Set ‘taxonomy’, ‘term’, and ‘term_id’ to the * first taxonomy other than ‘post_tag’ or ‘category’. */ … Read more

How can I filter a query by post id?

So you want the values 108,78,90 corresponding to the meta key ‘areas’ for the post with ID 94? First retrieve those IDs: $the_post_id = 94; $area_ids = get_post_meta( $the_post_id, ‘areas’, false ); //Make sure they’re all positive integers $area_ids = array_map( ‘absint’, $area_ids ); if( $area_ids ){ //We have IDs, retrieve posts $areas = get_posts( … Read more

how to show only catergory titles on a page in wordpress

You will need to combine get_categories() and wp_query First you should get all categories and loop through each one of them. Inside the loop you need a wp_query to get the title and the image of the latest post per category. At last you should reset the post data. Place the code below inside your … Read more

How to write short code with if else to get page_id?

I use this maybe helpfull <?php $title = get_the_title($post); $parent_title = get_the_title($post->post_parent); echo $title; echo $parent_title; ?> <?php global $post; //wordpress post global object if($post->post_type == ‘page’){ $content .= ‘<br /> This item is a page and the ID is: ‘.$post->ID; } elseif($post->post_type == ‘post’) { $content .= ‘<br /> This item is a post … Read more

How to query posts from single post format on Genesis framework

The taxonomy should be post_format and term should be post-format-link. Also simple taxonomy queries are deprecated since 3.1 in favor of tax_query: $args = array( ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => ‘post-format-link’ ) ) ); $recent = new WP_Query( $args );