Pagination go to first page if i’m on last post

Here is one idea for the previous post circle: $next_post = get_next_post(); $prev_post = get_previous_post_circle(); where we have defined this function: function get_previous_post_circle($in_same_cat = false, $excluded_categories=””){ $prev_post = get_previous_post($in_same_cat,$excluded_categories); if($prev_post){ return $prev_post; }else{ add_filter(‘get_previous_post_where’,’custom_get_previous_post_where’); $prev_post = get_previous_post($in_same_cat,$excluded_categories); remove_filter(‘get_previous_post_where’,’custom_get_previous_post_where’); if($prev_post){ return $prev_post; }else{ return ”; } } } and the filter function to remove the specific … Read more

Extract image src from a post and send it to an external form

There is no built-in way to extract an image/image-src from the post body. If the images are attachments you can do it with get_children or WP_Query, and wp_get_attachment_image_src. function get_image_src_from_content_101578($content) { global $post; $args = array( ‘post_parent’ => $post->ID, ); $images = get_children($args); foreach ($images as $img) { var_dump(wp_get_attachment_image_src($img->ID)); } } add_action(‘the_content’,’get_image_src_from_content_101578′); You could also … Read more

Custom search for custom post type, custom meta and search fields

If you want to extend your query, you should extend it through the pre_get_posts-filter. Then just do a “Custom Field” or meta query. add_action( ‘pre_get_posts’, ‘wpse105969_extended_search’ ); function wpse105969_extended_search( $query ) { // Make sure we got a search query // and we’re only modifying the main query. if ( ! $query->is_main_query() AND ” === … Read more

How to display category information from a custom post

To get the taxonomy term for this particular post, then what you need is wp_get_post_terms($post->ID, ‘yourtaxonomyname’) This will return an array of terms in the specified taxonomy for the post specified. The codex page is: http://codex.wordpress.org/Function_Reference/wp_get_post_terms If you’re after a specific term in a taxonomy get_term($taxonomy_name, $term_id). You can also get all terms for a … Read more

Custom templates for posts like for pages: page-{id} vs single-{id}

A) Single Post Templates: single-{post-type}-{post-name}.php It’s informative to check out the get_single_template() function. There we find the following template possibilities: “single-{$object->post_type}-{$object->post_name}.php” “single-{$object->post_type}.php” “single.php” In WordPress 4.7 this part will be added: “single-{$object->post_type}-{$name_decoded}.php” So it looks like you forgot the {$object->post_type} part in the template’s name. Example: The single template name for the post with the … Read more