• Hey there,

    my acf table fields plugin is broken since I made updates on WordPress core (4.7), acf(4.4.11) and acf:table fields(1.1.13). It actually says on the frontpage:

    Notice: Trying to get property of non-object in /homepages/27/d559574883/htdocs/dev/wp-content/themes/mondopazzo/frontpage.php on line 97

    The output of every line in this table is showing up like this. Before this error message there is showing up another table which looks good but is not related to this post_id. Very weird.

    I made the usual troubleshooting.

    The code looks like this:

    <?php
    // The Query
    $the_query = new WP_Query('post_id=106');
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		$table = get_post_meta(get_the_ID(), 'speisekarte_tabelle', true);
    		$table = json_decode($table);
    		echo '<ul class="pplan">';
    		foreach($table->b AS $row => $key) { 
    			echo '<li><span>'.$key->{'0'}->c.'</span><div>'.$key->{'1'}->c.'</div></li>';
    		}
    		echo '</ul>';
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter reyz1980

    (@kirill1982)

    screenshot of the described problem

    Plugin Author Johann Heyne

    (@jonua)

    Hello,

    whatever makes the different after the updates to trow that error, the problem may is the following. The error on line 97 perhaps is because $key in $key->{'0'}->c is not an object. $key is an array. So the code should look like $key[0]->c.

    Anyway…

    It is much easier to code using get_field()

    $table = get_field( 'speisekarte_tabelle' );
    echo '<ul class="pplan">';
        foreach( $table['body'] as $row => $key ) { 
            echo '<li><span>' . $key[0]['c'] . '</span><div>' . $key[1]['c'] . '</div></li>';
        }
    echo '</ul>';
    Thread Starter reyz1980

    (@kirill1982)

    Hey Johann,

    as I had a closer view on that issue, I’m still having problems with it. It now shows up all tables I create. Do you have an idea how to solve it with the_query. Thanks for your help.

    • This reply was modified 7 years, 10 months ago by reyz1980.
    Plugin Author Johann Heyne

    (@jonua)

    To get a single post by ID with WP_Query…
    $the_query = new WP_Query( array( 'p' => 106 ) );

    And without WP_Query…

    $post_id = 106;
    $table = get_field( 'speisekarte_tabelle', $post_id );
    echo '<ul class="pplan">';
        foreach( $table['body'] as $row => $key ) { 
            echo '<li><span>' . $key[0]['c'] . '</span><div>' . $key[1]['c'] . '</div></li>';
        }
    echo '</ul>';
    Plugin Author Johann Heyne

    (@jonua)

    Plugin Author Johann Heyne

    (@jonua)

    The reason showing all tables is maybe, that your WP_Query parameter does not exist and is ignored. So WP_Query returns all posts by default.

    Thread Starter reyz1980

    (@kirill1982)

    Hey Johann,

    thanks a lot. That has solved my problem.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘ACF: Table Fields after update broken’ is closed to new replies.