Error in genesis_get_global_post_type_name function

Community Forums Forums General Discussion Error in genesis_get_global_post_type_name function

This topic is: not a support question

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Gary Jones 1 year, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #56129

    Joshua
    Participant

    There might be another fix for this, and I’m sure it’s not something that most people run into… But, if you don’t have any posts and are perhaps creating a site without a blog, this function causes an error. I’ve added a conditional tag that fixes it:

    <?php 
    /**
     * Get the post_type from the global $post if supplied value is empty.
     *
     * @since 2.0.0
     *
     * @global WP_Post $post Post object.
     *
     * @param string $post_type_name Post type name.
     *
     * @return string
     */
    function genesis_get_global_post_type_name( $post_type_name = &#039;&#039; ) {
    
    	if ( ! $post_type_name ) {
    		global $post;
    		if( $post ) // ------------ added this to check for posts first
    			$post_type_name = $post->post_type;
    	}
    	return $post_type_name;
    
    }

    Thanks!

    • This topic was modified 1 year, 11 months ago by  nickthegeek.
    • This topic was modified 1 year, 11 months ago by  nickthegeek.
    #67483

    Gary Jones
    Moderator

    One of the fixes planned for 2.1 is to remove global $posts in favour of get_the_post() – that would ensure that $post is equal to *some* object.


    Changes in Genesis 2.1 – the ultimate guide to every single change in Genesis Framework 2.1, 2.1.1 and 2.1.2 (all 90 of them!) | @GaryJ

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.