Can’t get the previous and next posts permalink

You could use different code. As an example, this modified code from the Twenty Fourteen parent theme which i tested on other themes works well. Add this to a new file named template-tags.php <?php if ( ! function_exists( ‘wpsites_post_nav’ ) ) : function wpsites_post_nav() { $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : … Read more

Saving return value from the_author_posts_link()

The author posts link returns the author name which is linked to posts written by him. I think what you need is the author name of the post. It can be retrieved with <?php echo get_the_author(); ?> and if in case you need the link to the posts by this author then use: <?php echo … Read more

Fetching posts from wordpress function in ajax

If you read the documentation for locate_template you’ll see the problem. locate_template( $template_names, $load, $require_once ); $require_once (boolean) (optional) If true, the template file will be loaded with the php require_once function. If false, the template file will be loaded with the php require function. This parameter has no effect if $load is false. Default: … Read more

Custom content before post content

You can check the post type of the current post via get_post_type: function theme_slug_filter_the_content( $content ) { if( ‘post’ == get_post_type() ){ $custom_content=”YOUR CONTENT GOES HERE”; return $custom_content . $content; } return $content; } add_filter( ‘the_content’, ‘theme_slug_filter_the_content’ );

display post tags on single.php inside loop

You’re getting Array because that’s exactly what wp_get_post_tags returns; an array (and when you try and echo one in PHP it’ll simply output Array). As @Chip Bennet suggested, use the_tags() instead, which outputs an HTML string.

Exclude category from get_the_category

$cat_ids = wp_list_pluck( $cat, ‘term_id’ ); Once you get the category ids as you have mentioned above, you can search for the key having the category id 68 as $key = array_search(’68’, $cat_ids); Once you get the key, you can unset/remove that from the array as unset($cat_ids[$key]); Once that is removed, you can use the … Read more

Why doesn’t ‘continue’ work in page?

get_the_terms returns an array of terms – so $terms is an array. Therefore, your condition: if( $terms->slug != ‘product-gallery’ ) will always return false, and therefore skip every post every time. Try if ( in_array( ‘product-gallery’, $terms ) ) continue; The above is untested.

Get markup for post without loading into the template

I couldn’t figure out a WordPress way to do this and looking at the WP source, it looks like this probably will never really be possible. However, I was able to get a solution using vanilla PHP by redirecting standard output into a buffer and loading the buffer into a variable. $listings = new WP_Query(…); … Read more

get_posts() forcing ignore sticky posts on main loop

From the function reference for get_posts(): For full parameters list see WP_Query. From the WP_Query reference: ignore_sticky_posts (boolean) – ignore sticky posts or not (available with Version 3.1, replaced caller_get_posts parameter). Default value is 0 – don’t ignore sticky posts. Note: ignore/exclude sticky posts being included at the beginning of posts returned, but the sticky … Read more

Comments_template doesn’t work

Seems to me like you are trying to use the comments template out of context. The codex states: Loads the comment template. For use in single Post and Page displays. Will not work outside of single displays unless $withcomments is set to “1”. Unless you have a is_single() on the index.php or use the $withcomments … Read more