I've an meta field named "date"(custom field), now I'm trying to get all the posts that hasn't passed today's date, until now I did it with
if( strtotime(date("d.m.Y",strtotime(get_field("date", $post->id)))) < strtotime(date("d.m.Y")) ) { }
but it affected the pagination 2, so I need to change the get_posts() function to return the relevant results, but I'm not sure how to do it the doc talks about fetching the values with a match meta field value(which isn't exactly the case)
Related
How to get main meta_key's inner key? Inner key is on json format and need to get result in WordPress WP Query (With pagination)
Need solution on main WP_Query argument. Not in inner condition.
I have custom post type and meta stored in one meta key name is ="lp_listingpro_options" and on that meta key added multiple json data.
"Meta stored in databse on 'lp_listingpro_options' key is:"
I need to get all Plan_id is = 195
Can you please help me on that critical issue
a:35:{s:12:"tagline_text";s:15:"Atmen ist Leben";s:7:"gallery";s:0:"";s:12:"price_status";s:6:"notsay";s:10:"list_price";s:0:"";s:13:"list_price_to";s:0:"";**s:7:"Plan_id";s:3:"195"**;s:16:"lp_purchase_days";s:0:"";s:11:"reviews_ids";s:0:"";s:15:"claimed_section";s:7:"claimed";s:26:"listings_ads_purchase_date";s:0:"";s:30:"listings_ads_purchase_packages";s:0:"";s:4:"faqs";a:2:{s:3:"faq";a:1:{i:1;s:0:"";}s:6:"faqans";a:1:{i:1;s:0:"";}}s:14:"business_hours";a:5:{s:6:"Montag";a:2:{s:4:"open";s:5:"08:00";s:5:"close";s:5:"17:00";}s:8:"Dienstag";a:2:{s:4:"open";s:5:"08:00";s:5:"close";s:5:"17:00";}s:8:"Mittwoch";a:2:{s:4:"open";s:5:"08:00";s:5:"close";s:5:"17:00";}s:10:"Donnerstag";a:2:{s:4:"open";s:5:"08:00";s:5:"close";s:5:"17:00";}s:7:"Freitag";a:2:{s:4:"open";s:5:"08:00";s:5:"close";s:5:"17:00";}}s:21:"lp_medical_report_pdf";s:0:"";}
Look at the database meta_key stored image is
https://www.awesomescreenshot.com/image/15262224?key=c4c4290515f14fedc7ff39995cc682c7
That meta_value payload is not JSON. Rather, it uses php's serialization format for its objects and arrays. To look for a particular item in the meta_value, you load it into a php object and examine that object.
You can load it into a php value with deserialize(). But within WordPress you don't need to worry about that. If you use WordPress's get_post_meta() function it will return the item already deserialized.
Then you examine the array to find what you want.
$listingproOptions = get_post_meta( $postId, 'lp_listingpro_options', true );
print_r( $listingProOptions ); /* remove this line after testing */
if ( isset ($listingproOptions['Plan_id']) ) {
$planId = $listingproOptions['Plan_id'];
}
Say I have the following Post Statuses within WordPress:
Draft (default)
Pending Review
Pending Submission
Is it possible (and if so, how) to record the Post Edit screen's WYSIWYG editor's word count and save it as a database entry / custom field (for later reference) when the Post Status changes from 1 to 2, and then from 2 to 3?
Here's a screenshot to clarify what I mean by the word count: WordPress Post Edit screen word count.
Just before to change your post state, get your post data and take your content and try with this function to get the count words:
<?php str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) ?>
After this, record your custom field with this:
<?php add_post_meta($post_id, $meta_key, $meta_value, $unique); ?>
I think the image you show it count words with JavaScript, not with PHP.
I need to add a post meta keeping and I want the value to be unique, but according to the add_post_meta() codex there is only the option to set the key as unique. Can I do the same with the value?
The only solution I found is to check the post meta doing a get_post_meta(), then search into the array for a duplicate value, but maybe it's too intricate.
Check it manually over an Database query like:
$search = "What you searching for?";
if($wpdb->get_var($wpdb->prepare("SELECT COUNT(`meta_value`) FROM $wpdb->postmeta WHERE `meta_value`=%s", $search)) == 0) {
// Dont exists,.. Add a new post meta for example
}
I can't figure out why wp_category_checklist doesn't accept selected categories parameter when i pull data out of the database.
I have custom table in databse and in that table one of the fields is called
post_category
In this field i have comma separated list of categories id's and this list is just like this i copied numbers below directly from my table.
136, 8, 46, 9
The problem is that i want to use wp_category_checklist on my plugin page and to select those categories that are with id's from database field but function for some reason doesn't accept that parameter when it's pulled from database.
So to get my field values from database i use this
$item['post_category'];
And this returns categories id's, if i echo or print_r it i would get this
$cats = $item['post_category'];
echo $cats;
print_r($cats);
output on both is 136, 8, 46, 9
So by this results and by reading wp_category_checklist codex page i guess if i use this
wp_category_checklist(0, 0, $cats);
I will get categories that match id's with numbers from my field checked
But no it's not working, any reasons why?
$arr = explode(",",$cats);
wp_category_checklist(0, 0, $arr);
Third parameter is array.
I'm using Verve Meta Boxes. I want to make a menu out of one of the custom fields. How can I return all of the custom field values? For example, if I had a custom select field called "fruit" and as options I have "apples", "oranges", and "bananas", how could I get a complete list of those values, as an array perhaps? I can get the ones associated with a post:
get_post_custom_values('fruit')
…but I can't work out how to get the whole list.
Thank you in advance!
In case someone still wondering:
global $wpdb;
$results = $wpdb->get_results( 'SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key LIKE "FIELD_NAME"', OBJECT );
Just make sure your postmeta table is "wp_postmeta" (default) and change FIELD_NAME with the name you created for the field in the admin.
You could do it the regular wordpress way by using the get_post_meta function in your loop.
Try this one out:
$fruits = trim(get_post_meta($post->ID,'fruits',true));
$fruits_array = explode(',',$fruits);
foreach($fruits_array as $f){
echo $f.'<br/>';
}
Basically you need to separate your fruits name with comma in your custom field so that you will be able to explode them into array and echo the values one by one.
Thanks,Dave
I wasn't able to find an elegant solution. What I ended up doing was loop through all of the posts and kept a record of unique values as I can across them, creating an array. Then I used that array to make my navigation.