How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?

You can use the following filter: add_filter(‘wp_list_pages’, ‘foo_bar’); function foo_bar($html){ //Create a regex pattern to identify the LI element with preg_match //Create another pattern to identify the class attr and alter it with preg_replace return $html; } As I’m not familiar with the exact elements you are working with, I can’t write up a regex … Read more

How to update custom field of a posts in a particular category

Use get_posts to get all the posts in this category, then loop over it and update the post meta for every post. <?php //get_posts uses same parameters as WP_Query hence using ‘category_name’ $tut_posts = get_posts(array(‘category_name’=>’tution’, ‘post_status’=>’publish’)); $url = //some youtube video url here if(!empty($tut_posts)){ foreach($tut_posts as $tut_post){ update_post_meta($tut_post->ID, ‘video’, $url); } } Please check if … Read more

WP Query and multiple pages

Because your posts are only saved whithin the $promo var and not in the $wp_query global var. I recommend you to use get_posts() http://codex.wordpress.org/Template_Tags/get_posts

WP Query get only 1 post (sticky, not sticky etc)

Why don’t you use a fat-free $wpdb->get_var() for the task? global $wpdb; $ID = $wpdb->get_var(“SELECT `ID` FROM {$wpdb->posts} WHERE `post_type`=’post’ AND `post_status`=’publish’ ORDER BY `post_date_gmt` DESC LIMIT 1;”); $post = $ID ? get_post($ID) : null; // Now get the actual post This is way more efficient and light-weight. Without all the bells and whistles of … Read more