How to create an overview of posts with the same tag?

foreach( $posts_array as $post ) { echo the_title(); } I think the problem is you call the_title() without setup_postdata first If I were you, I’ll simply use $post->post_title. foreach( $posts_array as $post ) { echo $post->post_title; } This is because you are “get_posts”ing within a loop, and setup_postdata will change global variable $post which is … Read more

Query custom posts from custom taxonomy

You should access global variables in php using global keyword.It makes variable( or object, array) visible inside current function we are dealing with. In function wms_output_home_slides you are using $post global variable directly instead access it using global keyword as following. function wms_output_home_slides($cat) { // $cat=”homeslide” global $post; // You Code Goes here } Find … Read more

How to exclude custom fields from search queries?

If I understand you correctly, you need to have post metas in your query. This is where the meta_query parameter of the WP_Query class comes to help. The meta_query is an array of arrays. Example from the codex: $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => … Read more

Select min/max meta from query

You need subqueries. This is really a SQL question but as I know no way to do this with native WordPress functions without looping and running multiple queries here you go. $querystr = ” SELECT DISTINCT {$wpdb->posts}.ID, {$wpdb->posts}.*, (SELECT min(cast(meta_value as unsigned)) FROM {$wpdb->postmeta} WHERE meta_key=’_wp_price’ AND meta_value IS NOT NULL AND meta_value <> 0 … Read more

Different layout based on post amount?

for a standard query, you can check the amount of posts with: all posts for the query: $wp_query->found_posts and the posts on the page: $wp_query->post_count use that with a conditional statement to switch to the different layouts. example: <?php if ( have_posts() ) : //start of the loop// if ( $wp_query->found_posts <= 4 ) { … Read more

How to display only one category in a custom post type?

Something like this should work but you haven’t stated where you want to display the CPT pages for games. function display_games_archive( $query ) { if ( !is_admin() || $query->is_main_query() && is_post_type_archive( ‘portcat’ ) ) { $query->set( ‘category__in’, ‘games’ ); return; } } add_action( ‘pre_get_posts’, ‘display_games_archive’, 1 );