Will appreciate a response with my example.
I saw this post, http://wordpress.org/support/topic/sort-posts-by-custom-field-value-1?replies=3 but it doesn’t really make sense
Ok, so I am trying to follow your example as
apply_filters( 'wck_cfc_unserialize_fields_'.$studyoptions, false );
add_filter( 'wck_cfc_unserialize_fields_studyoptions', 'wck_change_unserialize_arg' );
function wck_change_unserialize_arg( $bool ){
return true;
}
echo "Gender".$studyoptions_gender_1;
studyoptions being the Meta Name of my Meta Box Arguments
gender being the Field Title I need
I am not having any luck…
Hi,
I’ll assume that you have a single metabox with the “Meta name” argument is “studyoptions” and that you have a radio button field “Gender”. If I’m wrong replace with the right values:
to make the values in each field store in its individual meta you would add:
add_filter( 'wck_cfc_unserialize_fields_studyoptions', 'wck_change_unserialize_arg' );
function wck_change_unserialize_arg( $bool ){
return true;
}
notice I don’t have the apply_filters line like in your example.
Now if you already have values in your metabox make sure you save them again so they can save also in unserialized form.
Your query args should look like this:
$gender = $_GET["gender"];
$args = array(
'post_type' => 'study',
'posts_per_page' => $postperpage,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'meta_key' => 'studyoptions_gender_1',
'meta_value' => $gender,
'paged' => $paged );
Hope this helps!
Hi madalin,
Thanks for coming back to me.
Doesn’t work for me.
My Meta Box Meta name: StudyOptions (notice Capitals)
My field title is gender and is a radio with 2 options (Male,Female)
I’ve added this above my query $args
add_filter( 'wck_cfc_unserialize_fields_studyoptions', 'wck_change_unserialize_arg' );
function wck_change_unserialize_arg( $bool ){
return true;
}
and
$gender = $_GET["gender"];
$args = array(
'post_type' => 'study',
'posts_per_page' => $postperpage,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'meta_key' => 'studyoptions_gender_1',
'meta_value' => $gender,
'paged' => $paged );
without success (no results found).
$gender is passed properly (ie Male or Female).
The query works without the meta_key/value
I am using version WCK Custom Fields Creator 1.0.4
I have edited a study (my CPT) and re-saved the values.
This is something that I am also worried about, I have 800+ Study already in the DB. Using your method, will I need to edit each of them and re-save for the values to be saved unserialized?
will appreciate help/clarification
Hi,
Please install the latest version of the WCK – Custom Fields and Custom Post Types Creator plugin (http://wordpress.org/support/plugin/wck-custom-fields-and-custom-post-types-creator) In version 1.0.4 we do not have that filter that you are trying to use.
You should remove the WCK Custom Fields Creator 1.0.4 plugin and then install the WCK – Custom Fields and Custom Post Types Creator plugin. You shouldn’t have any problems in the upgrade process and all your custom fields should still be there but please make a backup of your site before doing this.
Hi I have a similar problem. I have a
metabox:Social Links
metabox arguments with meta name: social
I have two fields facebook,twitter linked to posts. I can see them and their default values ‘#’ when I create a post. So I assume the set up part works. Now I write a function
$args = array(
'post_type' => 'post',
'category_name' => 'directors',
'orderby'=> 'id',
'posts_per_page' => 1,
'order' => 'asc'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) : $post_query->the_post();
$social = get_post_meta( get_the_ID(), 'social', true );
foreach ($social as $link) {
echo $link['facebook'] . '<br/>';
echo $link['twitter'] . '<br/>';
}
endwhile;
}
The function echos nothing when called. I am not sure where I went wrong