Wordpress and the syntax - wordpress

$users = get_users(array('role' => '','orderby' => 'meta_value','meta_key' => 'description'
,'order' => 'ASC','meta_query' => array(array('orderby' => 'meta_value'
,'meta_key'=> 'nummer','order' => 'ASC', ))));
Working on a website and need to sort players by numbers and position they play in floorball. The code work separately but not together can anyone help?

Could you be more specific please. Anyway you have a comma in addition at the end.
$users = get_users(array('role' => '','orderby' => 'meta_value','meta_key' => 'description','order' => 'ASC','meta_query' => array(array('orderby' => 'meta_value','meta_key' => 'nummer','order' => 'ASC'))));

Related

How to add filter to meta_query like finding only Roma Numeric

I have some situational problem with meta_query. Customer Search IV, but result is included prIVate (original word is private). I want to show only IV (roma numeric) included post. My meta_query search from Title, sub title and description in Custom plugin. I found REGEXP but I couldn't find a correct way to find Roam numeric from title, sub-title and description.
Customer can find only Roma Numeric also they can find any words etc.
$args = array(
'numberposts' => -1,
'category' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'title',
'value' => $search_term,
'compare' => 'LIKE',
),
array(
'key' => 'sub-title',
'value' => $search_term,
'compare' => 'LIKE',
),
array(
'key' => 'description',
'value' => $search_term,
'compare' => 'LIKE',
)
),
'post_type' => 'gallery',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts = get_posts($args, ARRAY_A);
Regular expression should include the roman numbers as follows (assuming the $search_term only includes the requested roman number:
$regEx = '/(' . strtoupper($search_term) . ')/g';
I solved my problem using regex to Title, Description and sub title. It's not good idea still looking for best answer.
$tempFlag = false;
foreach (explode(" ", $description) as $temp) {
if (preg_match('/^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/', $temp)) {
if (in_array($temp, $romeNumber)) {
$tempFlag = true;
}
}
}

How to search for users in WP with serialized meta values

I can get users using $all_users = get_users(['meta_key' => 'first_name', 'meta_value' => 'john']); but I have a small problem now, as the meta value for feature I am trying to fetch is serialized.
I have copied a row from the table as shown below.
103 wp_capabilities a:1:{s:12:"cs_candidate";b:1;}
I can get the value and unserialize it, but not sure if there is a way to do this in WP.
UPDATE:
To add more clarification, I am referring to this page https://codex.wordpress.org/Function_Reference/get_users or the below function to be exact:
<?php $args = array(
'blog_id' => $GLOBALS['blog_id'],
'role' => '',
'role__in' => array(),
'role__not_in' => array(),
'meta_key' => '',
'meta_value' => '',
'meta_compare' => '',
'meta_query' => array(),
'date_query' => array(),
'include' => array(),
'exclude' => array(),
'orderby' => 'login',
'order' => 'ASC',
'offset' => '',
'search' => '',
'number' => '',
'count_total' => false,
'fields' => 'all',
'who' => ''
);
get_users( $args ); ?>
The 'meta_value' => '', part in the field is serialized a:1:{s:12:"cs_candidate";b:1;}
You can't search unserialize an search at the same time, I'm afraid. Searching in serialized data is always a bit of a hassle.
If you are certain of structure of the data you are searching, you could do something like:
$meta_args = [
'key' => 'wp_capabilities',
'value' => 'cs_candidate";b:1',
'compare' => 'LIKE'
];
$users = get_users(['meta_query' => $meta_args]);
It's anything but pretty, but should do the trick.

Accessing value of wp_customize setting

So, I've got the following code:
function themename_customize_register($wp_customize){
// Display date
$wp_customize->add_section('display_date_section', array(
'title' => 'Datum weergeven',
'description' => 'Wil je de datum weergeven?',
'priority' => 120,
));
$wp_customize->add_setting('display_date', array(
'default' => 'value1',
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('display_date_section', array(
'label' => 'Datum weergeven:',
'section' => 'display_date_section',
'settings' => 'display_date',
'type' => 'theme_mod',
'choices' => array(
'value1' => 'Ja',
'value2' => 'Nee',
),
));
}
add_action('customize_register', 'themename_customize_register');
How can I access the value of the setting? Right now whenever I try to access it (either through get_theme_mod or $wp_customize->get_settings) My main goal with the code is to let users have the ability to control wether they want to display the date or not. Can somebody help me? :D

How to add custom fields for WordPress using Codeigniter RPC

I am using Codeignitor's RPC to post to a wordpress blog which is working fine BUT I cannot get the custom fields working. I assume the custom_fields is not correct "wrapped up" for the call?
$thePost = array(array('title' => array('Aston','string'),
'description' => array('this is the description','string'),
'wp_author_id' => array('2','int'),
'mt_keywords' => array('personal finance, money management','string'),
'mt_text_more' => array('read more','string'),
'categories' => array(array('Small Business'),'array'),
'custom_fields' => array(array('key' => 'image','value' => 'Say Hello'),'struct')),
'struct');
$thePost = array(array('title' => array('Aston','string'),
'description' => array('this is the description','string'),
'wp_author_id' => array('2','int'),
'mt_keywords' => array('personal finance, money management','string'),
'mt_text_more' => array('read more','string'),
'categories' => array(array('Small Business'),'array'),
'custom_fields' => array(
array(
array(
'key' => 'your key',
'value' => 'value'
),
'struct')
),'struct')),
'struct');
Take a look at this thread http://wordpress.org/support/topic/add-custom-fields-to-a-post-using-xml-rpc
Basically it says that you should be using metaWeblog.newPost instead of the wp api.

AJAX in Drupal Forms?

How would you go about constructing a step by step form that uses AJAX through Drupal to pull the next form step?
For example,
Step 1:
I like Baseball
I don't like Baseball.
When that person clicks on either Like or Don't Like, I want to use AJAX to recognize and pull the next part of the form, remove/hide the first section since its not needed, and present the next section.
Example:
Step 1:
I like Baseball
*click
(fade out)
Step 2:
My favorite team is __________
The player I like most is __________
What is the best way to do this through Drupal Form API? I know how to build the forms and modules, but I have never used AJAX yet. I know a few things exist out there that are supposed to help, but I wanted to know if anyone here has done it and how they approached it.
You may want to give a look at the AHAH helper module.
usually i am create full form with fieldsets, then control them manually by jquery.
i assume there lot of ready to go modules in drupal, some of these:
http://drupal.org/project/conditional_fields / http://drupal.org/project/multistep
also: http://www.google.ru/search?q=drupal+multistep+ajax+form
If you don't want to write any code, and don't need the entered data to be drupal nodes, I suggest using the webform module. It has a pretty simple UI for building forms, and allows you do do multipage forms with conditional fields. You can then export the results as CSV, email them, etc.
I have made to solutions for this problem in drupal 7. First one I solve it with Ajax as was requested(if someone want I can convert this to drupal6), however it should be better to solve this using attribute #states. So also made a solution in the bottom using states.
How to solve this using Ajax:
function ajax_in_drupal_form($form, &$form_state)
{
$baseball = array(
'like' => t('I like Baseball'),
'unlike' => t('I don\'t like Baseball')
);
$form['step'] = array(
'#prefix' => '<div id="baseball-wrapper">',
'#suffix' => '</div>',
);
if ($form_state['values']['baseball'] == 'like') {
$form['step']['team'] = array(
'#type' => 'textfield',
'#title' => t('My favorite team is'),
);
$form['step']['player'] = array(
'#type' => 'textfield',
'#title' => t('The player I like most is'),
);
}
else if ($form_state['values']['baseball'] == 'unlike') {
$form['step']['other'] = array(
'#type' => 'textfield',
'#title' => t('What do you like'),
);
}
else {
$form['step']['baseball'] = array(
'#type' => 'radios',
'#options' => $baseball,
'#title' => t('Select your option'),
'#ajax' => array(
'callback' => 'ajax_update_step_callback',
'wrapper' => 'baseball-wrapper',
),
);
}
return $form;
}
function ajax_update_step_callback($form, $form_state) {
return $form['step'];
}
Here is the solution using #states(The preferred way of solving it):
function states_in_drupal_form($form, &$form_state)
{
$baseball = array(
'like' => t('I like Baseball'),
'unlike' => t('I don\'t like Baseball')
);
// step 1
$form['step']['baseball'] = array(
'#type' => 'radios',
'#options' => $baseball,
'#title' => t('Select your option'),
'#states' => array(
'invisible' => array(':input[name="baseball"]' => array('checked' => TRUE),
),
)
);
// step 2 like baseball
$form['step']['team'] = array(
'#type' => 'textfield',
'#title' => t('My favorite team is'),
'#states' => array(
'visible' => array(':input[name="baseball"]' => array('checked' => TRUE)),
'visible' => array(':input[name="baseball"]' => array('value' => 'like')),
)
);
$form['step']['player'] = array(
'#type' => 'textfield',
'#title' => t('The player I like most is'),
'#states' => array(
'visible' => array(':input[name="baseball"]' => array('checked' => TRUE)),
'visible' => array(':input[name="baseball"]' => array('value' => 'like')),
)
);
// step 2 I don't like baseball
$form['step']['other'] = array(
'#type' => 'textfield',
'#title' => t('What do you like'),
'#states' => array(
'visible' => array(':input[name="baseball"]' => array('checked' => TRUE)),
'visible' => array(':input[name="baseball"]' => array('value' => 'unlike')),
)
);
return $form;
}

Resources