WordPress.org

Forums

[resolved] Magic Fields duplicates php error (2 posts)

  1. TootsieRoll
    Member
    Posted 1 year ago #

    I'm trying to use duplicate a Magic Fields group and I just can't get it to work.
    Here' s the code that I am using in my template:

    <?php
    	$column_2 = getGroupOrder('column_2');
    	foreach($column_2 as $column_two){
    		echo get('column_2_news_headline', $column_two)."<br />";
    		echo get('column_2_news_paragraph', $column_two)."<br /><br />";
    	}
    ?>

    And it's outputting this pretty error:
    Warning: Invalid argument supplied for foreach()

    I read that I could get rid of the error but throwing an in statement in there like this:

    <?php
    	$column_2 = getGroupOrder('column_2');
    	if($column_2) {
    	foreach($column_2 as $column_two){
    		echo get('column_2_news_headline', $column_two)."<br />";
    		echo get('column_2_news_paragraph', $column_two)."<br /><br />";
    	}}
    	?>

    The error isn't there anymore, but it's not out putting my content either...
    I'm not super knowledgable in php yet, but I'd like to get better at it, can anyone help me?

  2. TootsieRoll
    Member
    Posted 1 year ago #

    I've sorted it out:

    <?php
    	$column_2 = get_group('Column 2');
    	if($column_2) {
    	foreach($column_2 as $column_two){
    		echo $column_two['column_2_headline'][1]."<br />";
    		echo $column_two['column_2_text'][1]."<br />";
    	}}
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic