This is my first question on StackOverflow! I'm a PHP and WP developer beginner, and I'm doing my best to learn and pull information together, but I'm stumped.
I'm using Ninja Forms for WordPress. I want to return a full list of users and have them display in the drop down selection. The code below is based off this: Foreach loop inside array.
$blogusers = get_users( array( 'fields' => array( 'user_email') ) );
$args = array(
'name' => 'Select User',
'edit_options' => array(
array(
'type' => 'select',
'name' => 'select_users_from_group',
'label' => 'Select a User',
'options' => array()
),
),
'display_function' => 'select_users_from_group',
'edit_function' => 'select_users_from_group_edit',
'sidebar' => 'template_fields'
);
foreach($blogusers as $key=>$user) {
$args['edit_options'][0]['options'][] = array(
// 'name' => $user=>user_email,;
);
}
if( function_exists( 'ninja_forms_register_field' ) ) {
ninja_forms_register_field('select_users_from_group', $args);
}
I know my foreach loop is no good, but I don't know what to do to make it work. It fails when I remove the comment.
Eventually, I'd like for another field to return a user_meta value based on the user selected here, but I have no idea where to even begin on that.
Any help is appreciated. Not looking for you to write it for me. I'd rather learn how it works. Thanks in advance!
Related
I am trying to build a custom element for WPBakery Page Builder with a dropdown where custom taxonomy elements (categories) are listed.
Unfortunately I end up with empty dropdown elements. What am I doing wrong here?
The $options array gets filled perfectly when I var_dump it.
$terms = get_terms(array(
'taxonomy' => 'team',
'hide_empty' => false,
));
$options = array();
foreach($terms as $team) {
$options[$team->name] = $team->slug;
}
This is my params array inside the vc_map() function:
'params' => array(
array(
'type' => 'dropdown',
'holder' => 'div',
'class' => '',
'heading' => 'Team',
'param_name' => 'category',
'value' => $options
)
)
We had the same problem today.
After four hours fiddling around and trying everything, we finally found out that we were using a reserved word as our param_name, it was post_category, which by the way, is not on the Codex's Reserved Terms page, even though it definitely was one of them.
label also isn't on the list, but given that the error and behaviour was exactly the same, I'd advice trying to switch it for something else.
I just found a wired thing on my website after v4.4 update. In my blog pages I use 2 functions to fetch comments.
First I use
wp_list_comments( array( "callback" => "checkout_comment", "type" => "comment") );
To fetch the comments only. Then I run a count check if any trackbacks exists by using
$trackback_count = get_comments( array(
'status' => 'approve',
'post_id'=> get_the_ID(),
'type'=> 'pings',
'count' => true)
);
and if the do exists the I show the trackbacks/pingsbacks like this
wp_list_comments( array( "callback" => "checkout_comment", "type" => "pings", "reply_text" => null, "format" => "html5") );
Now, after v4.4 update the comments are showing fine but the trackbacks list are not showing.
Can anyone tell me why? What I might need to change to fix this?
I had asked a question here a while back about setting up database populated dropdowns for SugarCRM. I received a really good answer and, after more php studies and a dev instance running, I decided to give it a shot. The instructions I followed can be found here. After I run the repair and rebuild, I would expect to see the custom field in my Fields list under the module in studio, but have not been able to find it. The module is named Makers (a1_makers as a database table). For good orders sake, there were no errors when I repaired/rebuilt after saving the files. Per the instructions, I first created a php file with a custom function to query the database (custom/Extension/application/Ext/Utils/getMakers.php):
<?php
function getMakers() {
static $makers = null;
if (!$makers){
global $db;
$query = "SELECT id, name FROM a1_maker";
$result = $db->query($query, false);
$accounts = array();
$accounts[''] = '';
while (($row = $db->fetchByAssoc($result)) !=null) {
$accounts[$row['id']] = $row['name'];
}
}
return $makers;
}
?>
Then, I set 'function' field in Vardefs to point to the function (custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php):
<?php
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'len' => '100',
'comment' => 'List of makers populated from the database',
);
?>
Unfortunately, there are no errors and the repair/rebuild runs fine. I am just unable to see the custom field when I go into studio. Can anyone please help point out what I may be doing wrong?
I would recommend checking existence of newly created field 'list_of_makers' in cache/modules/Maker/Makervardefs.php file. If new field definition exists in that file, try add 'studio' => 'visible' to custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php to get something like this:
<?php
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'studio' => 'visible'
'len' => '100',
'comment' => 'List of makers populated from the database',
);
Try to edit your custom/modules/Maker/metadata/editviewdefs.php manually and insert field definition by hand in proper place if everything above won't work.
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'studio' => 'visible'
'len' => '100',
'comment' => 'List of makers populated from the database',
'studio' => array(
'listview' => true,
'detailview' => true,
'editview' => true
),
);
I have a CakePHP controller like this:
$this->loadModel('Project');
$list2 = $this->Project->find( 'list', array(
'fields' => array('Project.project'),
'conditions' => array('Project.user_id' => $userId)
));
$this->set($list2, 'list2');
$this->loadModel('Distance');
if(!empty($this->request->data)){
$this->Distance->create();
if ($this->Distance->save($this->request->data)) {
$this->Session->setFlash('Saved.');
// $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('FAILED');
}
}else{
// $this->Session->setFlash('test');
}
and a view like this:
echo $this->Form->input('Distance.project', array('options' => $list2, 'label' => false, 'empty' => '(choose one)' ;
But I get inserted to the database the id of the project instead of the project name.
I never have such problems working with the fields - just with a list of data.
Any idea why it happens?
It's normal ... The $list2 it's and array ... and the values of the options are the indexes from that array.
If you want to insert only the project name you need to change $list2 with $list2['project_name']. You need to remove or replace the indexes of $list2.
LE: take iexiak example. He change also the code for you.
$list2 = $this->Project->find( 'list', array(
'fields' => array('Project.project'),
'conditions' => array('Project.user_id' => $userId)
)
);
This is because $list2 automatically creates a list of ID => project; and when you use that as input for your form it automatically creates the drop down to reflect this. This is generally the best practice, to link to ID's instead of to descriptions, as ID's do not change as often. The below should get you exactly what you want though:
$list2 = $this->Project->find( 'list', array(
'fields' => array('Project.project','Project.project'),
'conditions' => array('Project.user_id' => $userId)
)
);
I've been looking all over the web but I can't seem to find any examples and I've tried it but failed. I am using version 2 of the api and I want to find product that filters by a customer attribute like so...
$filter = array(
array(
'key'=>'custom_attribute',
'value'=>"463"
)
);
$products = $client->catalogProductList($session,array(
'filter'=>$filter
));
But I am getting all the products and not the specific product I am looking for. Is there anything I am doing wrong ? Is there anything I am missing ??
Try following code.
$complexFilter = array (
'complex_filter' => array(
array(
'key' => 'custom_attribute',
'value' => array(
'key' => 'eq',
'value' => '463'
)
)
)
);
$products = $client->catalogProductList($session, $complexFilter);