• Resolved youknowmenot

    (@youknowmenot)


    Hello and congrats on the great plugin, tried several event plugins and this one has the best recurring functionality, while also being very customizable.

    I’m running my own custom theme and it features several loops on the frontpage. Whenever I enter a location i.e localhost/location/MyCity, on a few of those loops an error shows up above them:

    Warning: Attempt to read property “location_label” on null in E:\Server\htdocs\wp-content\plugins\my-calendar\my-calendar-locations.php on line 1325

    The line in question is part of if is singular ‘mc location’:

    'lvalue' => $location->location_label,

    I do not know how to fix this, so currently I have just disabled all links leading to the location pages. My other issue is with breadcrumbs. Whenever I visit a single event or location, breadcrumbs go Your City -> -> Single Event, instead of Your City -> Events -> Single Event, is this fixable? My code:

    function get_breadcrumb() {
        echo '<a href="'.home_url().'" rel="nofollow">My City</a>';
        if (is_category() || is_single()) {
            echo "&nbsp;-ยป&nbsp;";
            the_category(' &bull; ');
                if (is_single()) {
                    echo "&nbsp;-ยป&nbsp;";
                    the_title();
                }
        } elseif (is_page()) {
            echo "&nbsp;-ยป&nbsp;";
            echo the_title();
        } elseif (is_search()) {
            echo "&nbsp;&nbsp;»&nbsp;&nbsp;Search Results for... ";
            echo '"<em>';
            echo the_search_query();
            echo '</em>"';
        }
    }

    Thank you for this plugin!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Joe Dolson

    (@joedolson)

    The error seems like it would happen if there was no location that matched the post ID; that’s a little unexpected. Is it possible you have some partially deleted locations in your database? Are the posts you’re visiting not visible in the Locations admin in My Calendar?

    As far as the breadcrumbs go, if you’re using a custom breadcrumb function, you’ll have to figure out what you need for that to work. First of all, you’d need to decide what ‘Events’ is going to link to in the breadcrumb, then insert that link instead of the_category() when you’re viewing an event or a location. The problem is that your code assumes that any post that matches is_single() will have categories; but is_single() matches all post types, whether they have categories or not.

    Thread Starter youknowmenot

    (@youknowmenot)

    I have tried other plugins and their locations, but even after creating a unique name – the error still exists and it appears on random posts on my sidebar (where I have the other loops). I don’t know what you mean by “partially deleted locations”. I have deleted locations in the past.

    And this happens only if I visit the location’s address (the post/page itself). I have loops for a sidebar “latest news” section where I pull the latest posts from different categories. That’s where the error shows up on random (not on all “latest-news” posts).

    Plugin Author Joe Dolson

    (@joedolson)

    Can you share a link? I’m not totally clear on the context where this is happening; it sounds a bit unusual.

    For the record, I can definitely prevent this error from occurring in a future release; but I’d like to figure out what the scenario is that’s triggering the error.

    Thread Starter youknowmenot

    (@youknowmenot)

    I’m running the site on a local xampp installation and I have nowhere to upload it to show you, I’ll make screenshots and paste you the loop code.

    Here is how it looks:

    View post on imgur.com

    Looking at one of the screenshots (Test Title), an upcoming events list is being generated but for another location, not the one that I have currently opened. My text excerpt is “Just another test post to check a few things” and then the Upcoming events part comes up. It would probably come up in the other one as well but it has a longer excerpt and no place to add more text.

    Other sections are fine, like this one:

    View post on imgur.com

    <?php
    $args = array(
        'post_type' => 'review',
        'posts_per_page' => 1,
        'cat' => '28',
    );
    $q = new WP_Query( $args);
    
    if ( $q->have_posts() ) {
        while ( $q->have_posts() ) {
        $q->the_post(); ?>
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php 
            the_title(); ?></a>
        <?php if ( has_post_thumbnail() ) : ?>
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php the_post_thumbnail('medium'); ?>
                </a>
                <?php endif; ?>
                    <?php
            the_excerpt(); ?>
    
    <?php
    
    $the_cat = get_the_category();
    
    $category_name = $the_cat[0]->cat_name;
    
    $category_link = get_category_link( $the_cat[0]->cat_ID );
    
    ?>
            Posted in <a href="<?php echo $category_link ?>" title="<?php echo get_the_category( $id )[0]->name ; ?>">
            <?php echo get_the_category( $id )[0]->name ; ?></a>
    Posted on <?php echo get_the_date(); ?> by <?php the_author_posts_link(); ?>
    <?php
        }
        wp_reset_postdata();
    }
    ?>

    I have cleaned the divs and text formatting to make it easier to read. This is the loop I use for the book review section. I was wondering if somehow the category IDs could be the problem. I could change those to category slugs instead.

    Plugin Author Joe Dolson

    (@joedolson)

    I’m trying to figure out how that loop would be calling any data at all about a location or an event; are you including a shortcode of some kind in the excerpt that’s getting run by some other filter?

    There’s just nothing I’m seeing in that code that tells me how it interacts with My Calendar; is this loop running on a custom template for a location, perhaps?

    Thread Starter youknowmenot

    (@youknowmenot)

    No, I’ve never run shortcodes. The side loops (latest-article-from-a-category sections) are part of the footer.php, while the main loop for the location is indeed in a custom single-mc-locations.php file.

    <?php
     get_header();
    ?>
    
    <?php
        if( have_posts() ){
    
            while( have_posts() ){
                
                the_post();
                get_template_part( 'template-parts/content', 'location' );
    
            }
        }
    ?>
    
    <?php
     get_footer();
    ?>

    And here is the content for the template part “location”:

    <?php           
            the_title(); 
        ?>
    <?php if ( has_post_thumbnail() ) : ?>
            <?php the_post_thumbnail('large'); ?>
    <?php endif; ?>
    <?php
    the_content();
    ?>
    <?php	
    edit_post_link( __( 'Edit Location', 'textdomain' ), '[', ']' ); ?>

    I stripped down all “cosmetic” divs for easier reading. I too fail to see what the relationship between these loops are. And keep in mind that this error pops up randomly on different loops. After uploading a new article today, it removed itself from the book reviews section screenshoted in my previous post and appeared in another one:

    View post on imgur.com

    Whenever I go to localhost/mc-locations/locationname it redirects me to localhost/locations/locationname and the result is the same. Could it be something left over from other event plugins, even though the error is directing towards My Calendar file? I can get over not having location pages, but that phantom error is bizarre.

    Plugin Author Joe Dolson

    (@joedolson)

    I think this stems from my not restricting the filter on ‘the_content’ to only the main query; I’ll push an update with that change. Although I’m not 100% sure of that, because it seems like your code shouldn’t be running that filter in those loops.

    Regarding the redirect: that’s presumably because you’ve changed the post type slug from ‘mc-locations’ to ‘locations’?

    Thread Starter youknowmenot

    (@youknowmenot)

    Thank you for the time. My locations will remain disabled and I will remove all links to them. This is still the best plugin I’ve tried, at least for my needs so thank you.

    Thread Starter youknowmenot

    (@youknowmenot)

    The bug is fixed with the new update, good job. ๐Ÿ™‚

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Breadcrumbs and theme conflicts’ is closed to new replies.