I had a small problem in my wordpress code I need to show a wordpress wp_editor in my page where it has array of values.the values are defined like the following
$fields[] = array(
'name' => __('Class', 'my-theme'),
'desc' => __('', 'my-theme'),
'id' => 'class'.$n,
'std' => ( ( isset($class_text[$n]['class']) ) ? $class_text[$n]['class'] : '' ),
'type' => 'text');
When I define my wp_editor like the above array it doesn't display where I want. Instead all the editors displayed at the top before any content in all pages.
I tried like the following set of array for the editor:
$fields[] = array(
'name' => __('My Content', 'my-theme'),
'id' => 'sectioncontent'.$n,
'std' => ( ( isset($class_text[$n]['content']) ) ? $class_text[$n]['content'] : '' ),
'type' => wp_editor( '', 'sectioncontent'.$n ));
Attached the image of my problem:
Cause
By default wp_editor prints the textarea that's why you cannot assign it to any variable or array.
Solution
you can use output buffering of php to get printed data in variable like this:
ob_start(); // Start output buffer
// Print the editor
wp_editor( '', 'sectioncontent'.$n );
// Store the printed data in $editor variable
$editor = ob_get_clean();
// And then you can assign that wp_editor to your array.
$fields[] = array(
'name' => __('My Content', 'my-theme'),
'id' => 'sectioncontent'.$n,
'std' => ( ( isset($class_text[$n]['content']) ) ? $class_text[$n]['content'] : '' ),
'type' => $editor); // <-- HERE
Looks to me like you're using Redux Framework to set up your theme/plugin option page - If you are looking to add the default Wordpress WYSIWYG (What You See Is What You Get - the same editor from the edit post page in the backend) editor in there you'll need to use the type: 'editor'.
It can be confusing - the wp_editor() function you are using is the right place to start if you were setting up this options page from scratch, but you'd need to do quite a bit of work to have it display where and how you want it. Redux et al make this quite a bit easier for you by generating the editor for you, so instead of you using the wp_editor function at all you just tell Redux that you want an editor field called 'My Content' to be one of the fields on the page.
The documentation for the editor field is here: https://docs.reduxframework.com/core/fields/editor/
If I am correct that you are using redux, the correct code to replace what you have is:
$fields[] = array(
'name' => __('My Content', 'my-theme'),
'id' => 'sectioncontent'.$n,
'std' => ( ( isset($class_text[$n]['content']) ) ? $class_text[$n]['content'] : '' ),
'type' => 'editor');
To explain the other parts of this field array:
'Name' will be what shows up in the label for this field. In this case you are using the localization functions in wordpress (__()) to get a phrase from the local dictionary in the 'my-theme' domain.
'id' is what you will use to retrieve what has been entered into this field. It will also affect the ID attribute assigned to the HTML elements in the options page.
'std' is the default for the field, which will be the value of the field when the options page is first displayed, before the user has set any options
On the editor documentation page linked above, you'll see the details of various other options you can define, like whether to show Media Upload buttons, and whether to run the input through wpautop to replace line breaks in the editor with <p> tags (by default both of these are true).
Related
My goal is to get a signed-in user to select a color( via front end form and saved in ACF user meta field group) that will be applied to another user meta field inside a repeater. The field must be the same for each row inside the repeater ( for front-end design reasons ). I am using ACF pro, and a plugin called ACF Front end admin (let's call it FEA from now on) for the front-end form. I'm pretty new to PHP and have referenced ACF & FEA's s documentation, which can be found below, spin up a custom function. I am currently running this through the code snippets plugin if this helps. I've run an error log and nothing related to this shows. Tried running this through wp-config and it crashes my site.
Front end admin documentation
ACF documentation - update sub field
ACF documentation - getting values from a user
Edit, Additional information:
ACF Field composition of 'button color' (color of the buttons that user wants displayed in front end, and saved as user meta):
acf_add_local_field_group(array(
'key' => 'group_60000aaa00000',
'title' => 'Color Selector',
'fields' => array(
array(
'key' => 'field_60000aaa00000',
'label' => 'Button color',
'name' => 'button_color',
'type' => 'color_picker',
Button color in repeater field that needs to updated based on the above mentioned 'button_color' meta value:
acf_add_local_field_group(array(
'key' => 'group_70000bbb00000',
'title' => 'front end user profile',
'fields' => array(
array(
'key' => 'field_70000bbb00000',
'label' => 'Quick Link selector',
'name' => 'quick_link_selector',
'type' => 'repeater',
),
array(
'key' => 'field_70000ccc00000',
'label' => 'repeater button color',
'name' => 'repeater_button_color',
'type' => 'text',
The title of the forum is: "QL color selector form" (created through the FEA plugin) and has a short code of [frontend_admin form="3030"] if this helps.
I'm running the following code with no luck and would really appreciate any help!
/// Hooks into any(?) form and does something
add_action('acf_frontend/save_user', 'retrieve_colors_2_update', 10, 2);
function retrieve_colors_2_update( $form, $user_id ) {
$user = get_user_by('ID',$user_id);
//get important fields
$btn_color = get_field('button_color', 'user_' .$user_id);
//// update a repeater loop (ACF)
if( have_rows('quick_link_selector', 'user_'.$user_id) ) {
$i = 0;
while( have_rows('quick_link_selector') ) {
the_row();
$i++;
update_sub_field('repeater_button_color', $btn_color );
}
}
}
I like to do a simple thing with my custom meta box, but i d'ont find a (easy) solution for this problem.
I have done a custom post type with some meta boxes => text, textarea, select fields, ect.
all work just fine. Now if i set the button to sold,(see code excerpt from the radio array below) the text(div) should be red; if i set it to for_sale, it should be green.
but i have no idea how to do this, i mean there are this two states possible. nothing else.
and that is what i want.
but the html output is only text. or text in a html-tag, this i can style with css, but it would be red, or it is blue, green what else i sett it.
is there a simple thing, like a class to set for each value? i c'ant find an answer. i hope i have explained it understandable. thanks so much for taking time for this.
array(
'label' => 'Status',
'desc' => 'product status',
'id' => $prefix.'radio_status',
'type' => 'radio',
'options' => array (
'one' => array (
'label' => 'Product for sale',
'value' => 'for_sale'
),
'two' => array (
'label' => 'Product is sold',
'value' => 'is_sold'
),
),
),
EDIT :)
<span class="saleBox"><span class="noBox"><?php echo $post_meta_data['custom_radio_status'][0]; ?></span></span>
Thats the HTML, and what i get is the value thats setted.
<span class="saleBox"><span class="noBox">for sale</span></span>
or then: *soled
So i need a Output with a true-value, or class, ID,... something that i can adress with css.
A good idea that works. only thing that i doesen't understand is, is must call the array.
<?php $post_meta_data = get_post_custom($post->ID); ?>
if i call only the specific data:
<?php get_post_meta($post->ID, 'custom_radio_status', true) ?>
for me, it won't. or i made a typo. it doesen't matter i works!
thank you mr. Maguire
Put a conditional statement, something like:
<span class = "
<?php
if ($post_meta_data['custom_radio_status'][0] == "is_sold"){
echo "red_class";
}else{
echo "green_class";
}
?>
">
I'm using Yiibooster and the TbGridView to show some results. I'm also using the following code to provide smart looking icons to a view, update and delete link.
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/item/view", array("id"=>$data["id"], "sector" => $data["sector"]["slug"],"title" => $data["slug"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("/item/update", array("id"=>$data["id"]))',
'deleteButtonUrl'=>null,
)
What I'd like to do is basically be able to show another button in there or in replace of the delete button. I'm just unsure how (or where specifically) I need to code the values for the this button.
I'm currently looking at the TbButtonColumn.php file and tried just adding a button just to see if it would work it didn't.
What would be the correct process to to do this?
Thanks in advance
Jonny
There is a buttons parameter for additional buttons, it is in docs od CButtonColumns, here is sample from link:
array(
'class'=>'CButtonColumn',
// Template to set order of buttons
'template' => '{postview} {preview}',
// Buttons config
'buttons' => array(
'postview' => array(
'label' => '...', // text label of the button
'url' => '...', // the PHP expression for generating the URL of the button
'imageUrl' => '...', // image URL of the button. If not set or false, a text link is used
'options' => array(...), // HTML options for the button tag
'click' => '...', // a JS function to be invoked when the button is clicked
),
'preview' => array(
// Another button config
),
),
),
NOTE: This is example for CButtonColumn but TbButtonColumn is a subclass of CButtonColumn, so everything applies to both.
I am helping a buddy out and modifying his Wordpress portfolio for him. I don't use php very often so this might be something simple.
In a template I am calling the Wordpress the_field() method like so:
<?php echo the_field('full_text'); ?>
This is outputting the content of the full_text just fine however the full_text does contain an <a> tag which is not being generated as a link and is showing up as:
The Link
instead of actually generating the link.
What do I need to do to get any HTML contained in the full_text field to show up as HTML and not plain text?
Edit
In custom_fields.php I've found:
array (
'key' => 'field_4',
'label' => 'Full Text',
'name' => 'full_text',
'type' => 'textarea',
'order_no' => 2,
'instructions' => 'Write about this item.',
'required' => 0,
'conditional_logic' =>
array (
'status' => 0,
'rules' =>
array (
0 =>
array (
'field' => 'null',
'operator' => '==',
'value' => '',
),
),
'allorany' => 'all',
),
'default_value' => '',
'formatting' => 'br',
),
It seems like you're using Advanced Custom Fields. If so, you need to turn off the "filter content" setting to get the link to show up.
Thanks to mcrtr I was informed that the template he was using was using Advanced Custom Fields digging deeper I found the field full_text was of type textarea by changing it to wysiwyg it no longer outputted as plain text.
When setting up the field, change the formatting option to HTML instead of none and it'll keep the <a> tag around your link.
You don't need to change it to WYSIWYG in order to keep links as links in ACF.
I'm using the WPAlchemy class to create a metabox. I want to place this metabox in a number of post editors in the backend.
Currently it's working just fine with the following code:
$video_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_videoMeta',
'title' => 'Videos',
'types' => array('characters','homepage'),
'template' => THEMEASSETS . '/functions/video_meta.php'
));
What I want to do though is additionally place the metabox on the post editor for post ID #22. Supposedly the following code should work:
$video_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_videoMeta',
'title' => 'Videos',
'types' => array('characters','homepage'),
'template' => THEMEASSETS . '/functions/video_meta.php',
'include_post_id' => 22
));
But it doesn't work unless I add in 'page' into the array of post types, which adds the metabox to all pages (not just post ID 22).
Is there a way to use poth the types and the include post ID arguments?
I had the same issue. Acutally, I had set a metabox to two custom post types and wanted it to be displayed on a specific page.
$video_metabox = new WPAlchemy_MetaBox(array(
'id' => '_videoMeta',
'title' => 'Videos',
'types' => array('characters','homepage', 'page'),
'template' => THEMEASSETS . '/functions/video_meta.php',
'include_post_id' => 22
));
Just add the bult in 'page' post type and everything should work fine. It did for me.