redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

How do I? foreach loop of categories

Open TuxReports opened this issue 12 years ago • 4 comments

Hi

I wasn't sure where to post this question because it is more of a question regarding "how to" and I didn't find it in the documents.

I have a foreach loop: $categories = get_categories( array( 'hide_empty' => '0' ) ); foreach ( $categories as $category ) { $name = $category->name; $slug = $category->slug; echo '<tr><td><label for="xf_category_forum_id_' . $slug . '">'; echo $name . ' </td>'; echo '<td><input name="xf_category_forum_id_' . $slug . '" type="text" maxlength="4" size="4" id="xf_category_forum_id_' . $slug . '" value="' . $xf_options['xf_category_forum_id'][ $slug ] . ' " /></td></tr>'; echo "</label><br />"; }

I'm trying to figure out how to replicate this in redux.

This is the label just before it.

<label for="xf_category_forum_id_default"> <td>Default</td> <td><input name="xf_category_forum_id_default" type="text" maxlength="4" size="4" id="xf_category_forum_id_default" value="<?php echo $xf_options['xf_category_forum_id']['default']; ?>"/></td> </label>

Now, the end result is the return of categories then the WP admin can add in a forum id next to the category. Since some installs only have 1 category then 1 textbox is returned. If 10 then 10 ...

If there are documents on foreach loops and this type of behavior then please let me know.

screen shot 2014-05-12 at 1 16 18 pm

TuxReports avatar May 12 '14 20:05 TuxReports

use the 'data'=>'categories' attribute as had in the docs. ;)

dovy avatar May 12 '14 20:05 dovy

Thank you.

http://docs.reduxframework.com/redux-framework/fields/text/

No 'data' argument on that page but tried and it almost works. Not all of the categories are being returned. The categories without posts are not being returned.

array( 'id' => 'xf_category_forum_id', 'type' => 'text', 'title' => __('Enter the forum id', 'xenword_options'), 'desc' => __('The forum id may be found by hovering over the forum title.', 'xenword_options'), 'data' => 'categories', 'default' => '2' ),

TuxReports avatar May 13 '14 13:05 TuxReports

There is no data argument doced for the text field, as - as far as I know - i t was never intended for use with the text field.

Either way, you want to use the args argument in your field code, to pass any of the arguments listed here: http://codex.wordpress.org/Function_Reference/get_categories. hide_empty to false, most likely.

kprovance avatar May 13 '14 17:05 kprovance

Multi-Text supports that. That's what you're looking for. ;)

dovy avatar May 13 '14 17:05 dovy