How can I query posts from multiple roles?

Just do the get_users() twice and merge the results: <?php $friends = get_users( array( ‘role’ => ‘friends’ ) ); $enemies = get_users( array( ‘role’ => ‘enemies’ ) ); $friends_n_foe = array_merge($friends, $enemies); $IDs = array(); foreach( $friends_n_foe as $person ) { $IDs[] = $person->ID; } $news = new WP_Query( array( ‘author’ => implode( ‘,’, $IDs … Read more

Meta_query with or without value

check if the $GET[‘rating’] is set ( isset($_GET[‘rating’]) or has any value. ( !empty($_GET[‘rating’]) if not, build the query fecthing all post without ‘meta_query’ for example: if ( (isset($_GET[‘rating’]) && !empty($_GET[‘rating’]) ) { // restrict $meta[] = array(( ‘key’ => ‘rating’, ‘value’ => $_GET[‘rating’] ); } if ( (isset($_GET[‘tax’]) && !empty($_GET[‘tax’]) ) { $meta[] = … Read more

Pagination doesn’t work in custom page template [duplicate]

Try the following and see how you go.. <?php global $paged; global $wp_query; $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(‘posts_per_page=10&post_type=your_post_type’.’&paged=’.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <!– do your loop output here, title, content etc –> <?php endwhile; ?> <?php previous_posts_link(‘&laquo; Newer’) ?> <?php next_posts_link(‘Older &raquo;’) ?> <?php $wp_query = null; $wp_query … Read more

Add a default meta_value to new posts

Add this to your functions.php in your template folder. <?php //Set Default Meta Value function set_default_meta_new_post($post_ID){ $current_field_value = get_post_meta($post_ID,’YOURMETAKEY’,true); //change YOUMETAKEY to a default $default_meta=”100″; //set default value if ($current_field_value == ” && !wp_is_post_revision($post_ID)){ add_post_meta($post_ID,’YOURMETAKEY’,$default_meta,true); } return $post_ID; } add_action(‘wp_insert_post’,’set_default_meta_new_post’); ?>

WordPress custom archive page

Of course it breaks. Pagination depends on the main query saved in the $wp_query object and you have overwritten that. When the next page load the ordinary wp_query that you have not overwritten will run and it won’t match the one you’ve altered. Create a filter for pre_get_posts to alter the main query. function pregp_wpse_97354($qry) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)