Get term name without a foreach loop

What about using: echo get_the_term_list( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); instead, to generate the HTML list? Or simply: the_terms( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); that’s a wrapper for get_the_term_list(). Also notice that you’re missing the is_wp_error() check, in your code snippet, because wp_get_post_terms() can return the WP_Error object, for an unknown taxonomy. But … Read more

Cannot retieve the_content() and the_author() – both returning empty strings

get_the_content and the_author have to be in a loop so you would need to use other functions to get the content you need global $wp_query; $post = $wp_query->post; $page_id = $post->ID; // page ID $page_object = get_page( $page_id ); // page stuff $author_id = $post->post_author; // author ID $page_content = $page_object->post_content; $author_name = get_the_author_meta( ‘display_name’, … Read more

single-{post_type}.php not working

according to your code, your cpt is “event”. You will either need to change the your php to single-event.php or change this line: register_post_type(‘event’, $args); to register_post_type(‘events’, $args); Usually they are the plural so the 2nd option is a better choice. With that being said, I always recommend adding namespace to avoid conflicts. Especially in … Read more

Insert sometext after first h3 in content

Note returning $content[0]; when !is_single() you’ll get non-exist errors. You can accomplish what you’re after with somthing like: add_filter(‘the_content’, function ($content){ if (!is_single()) return $content; $div = “🎅🏻”; return preg_replace(‘/<\/h3>/i’, “</h3>”.$div, $content, 1); }); note the third parameter of preg_replace() is the limit, setting to 1 will restrict the replace to the first match.

WordPress block editor embeds not working in theme (single.php)

That would be because they’re using oEmbed, not a shortcode. You should use the function the_content() to render the content of a post, as it applies all the things required to make embeds, shortcodes, etc work properly. If for some reason that’s not an option, you can apply the content filter. <?php echo apply_filters( ‘the_content’, … Read more

Custom seperate Single.php

This should help, if you need more info: http://codex.wordpress.org/Template_Hierarchy Simply put, WordPress looks for template files in the following order for single posts: single-{post_type}.php, single.php, index.php. If you want to override the standard single.php file, that’s how (for a custom post type only, as you’re using)

Single page not working for custom post type

Add this to your functions.php: /* Flush rewrite rules for custom post types. */ add_action( ‘after_switch_theme’, ‘bt_flush_rewrite_rules’ ); /* Flush your rewrite rules */ function bt_flush_rewrite_rules() { flush_rewrite_rules(); } Then change your theme to a different theme and then set it back again to your custom theme. This will flush the rewrite rule and making … Read more

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