Fatal error: Uncaught Error: Call to undefined function get_userdata()

Generally, forms should be handled on init action or later (mainly in a plugin file, maybe in the theme’s functions.php file, never in a tempalte file), so you can have access to WP functions. add_action( ‘init’, ‘search_form_submit’ ); function search_form_submit(){ $task_name = isset($_GET[‘taskname’]) ? $_GET[‘taskname’] : ”; $meta_key = ‘wp_tasks’; $args = array( ‘post_type’ => … Read more

Query for custom posts with a specific tag slug

Since tag is a taxonomy of a custom_post post type, the query could look like this: <?php $args = array( ‘post_type’ => ‘custom_post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => array( ‘tag1’, ‘tag2’, ), ), ), ); $posts = new WP_Query( $args ); See WP_Query Taxonomy Parameters.

$wp_query->current_post restarts from zero on paged pages

$wp_query->current_post holds information about current post in loop, not global set of posts. Numering posts across multiple pages is not available natively (as far as I know) and probably would be to unreliable (for example what if number of posts per page changes is customized to be uneven?). For specific implementation building custom numbering, based … Read more

Pagination for custom query on single.php

Well, for anyone else looking to solve a similar problem, I found this post, and it led me in the right direction: http://wordpress.org/support/topic/pagination-on-singlephp-causing-301-redirect?replies=9. I added this snippet of code to my functions.php, and I can paginate in custom queries without issue on single.php now. I don’t know enough about it to know what it does, … Read more

How to display images in related posts?

That is simple: <?php $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( ‘category__in’ => $category_ids, ‘post__not_in’ => array($post->ID), ‘showposts’=> 5, // Number of related posts that will be shown. ‘caller_get_posts’=> 1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo ‘<h3>Related Posts</h3>’; echo ‘<ul>’; while ($my_query->have_posts()) … Read more