Use get_post_types to query only custom posts types

Instead of creating a string try creating an array and check. $posttypes_array = array(); foreach ($post_types as $post_type ) { $posttypes_array[] = $post_type; } And then form the query as follows $buildArgsAllQuestions = array( // Add out new query parameters ‘post_type’ => $posttypes_array, //’post_type’ => $posttypes_array, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, );

query user display_name failed in a custom mysql query foreach

You should use all of the goodness of the wpdb object. #Create a new WPDB object for your custom DB $foo_db = new wpdb(‘username’,’password’,’database’,’localhost’); $query = (‘SELECT * FROM custom_table’); #Use the get_results method – You can return OBJECT(default), OBJECT_K, ARRAY_A, ARRAY_N $results = $foo_db->get_results($query, OBJECT); foreach($results as $row){ $user = new WP_User($row->user_id); } You … Read more

Any way to include custom fields in WP_Query results?

You may want to hook somewhere in the gazillion hooks available in wp-includes/query.php. I would suggest something like this: function my_always_get_post_custom( $posts ) { for ( $i = 0; $i < count($posts); $i++ ) { $custom_fields = get_post_custom( $posts[$i]->ID ); $posts[$i]->custom_fields = $custom_fields; } return $posts; } add_filter( ‘the_posts’, ‘my_always_get_post_custom’ ); In this way you … Read more

Upcoming Event: How do I sort database by custom date field, but ignore past dates?

You’re pretty close, but I wouldn’t be distracted by the ‘scope’ meta key. The following is untested. <?php $args = array( ‘post__not_in’ => array($donotrepeat), “post_type” => ‘event’, ‘meta_key’ => ‘_event_start_date’, // name of custom field ‘orderby’ => ‘meta_value’, “order” => ‘ASC’, “posts_per_page” => 1, ‘meta_query’ => array( array( ‘key’ => ‘_event_start_date’, ‘value’ => date(‘Y-m-d’), ‘compare’ … Read more

Custom category search box for WordPress

In every template file of your theme, even in the header.php you can put <?php $term = null; $btn = __(‘Search’); if ( is_category() ) { $term = get_queried_object(); } ?> <form method=”get” id=”search_form” action=”<?php echo home_url(); ?>”> <div> <input type=”text” value=”” name=”s” id=”s” /> <?php if ($term) { $btn = sprintf( __(‘Search in %s’), … Read more

Tell wordpress to show a single page instead of an archive

Here is a rough filter: add_filter( ‘template_include’, function($template) { global $wp_query; if (1 == $wp_query->found_posts) { global $wp_query; $type = $wp_query->get(‘post_type’) ?: false; $template_type = $type ? ‘single-‘ . $type. ‘.php’ : ‘single.php’; if ( locate_template($template_type) ) { return locate_template($template_type); } elseif ( $type && locate_template(‘single.php’) ) { return locate_template(‘single.php’); } } return $template; } … Read more