Tag Info

Hot answers tagged

5

I think, not 100% sure that this was the real reason the WP developers took this approach, but common sense tells me that serialize preserves the variable types and have a mini built in error detection, and json stores only string values { key : value }, so when you go back to PHP you will have to guess the format, or make a parser for it. This will force ...


4

Yes, do an INNER JOIN, something like this should work: $values = $wpdb->get_col($wpdb->prepare(" SELECT meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE meta_key= %s AND {$wpdb->posts}.post_status='publish'" ,$metakey )); I changed ...


2

I am tempted to close this as "subject to opinion" but I think there are a couple of good answers to the question. I am going to go with "history". 1) json_encode is relatively new in PHP core. json_encode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_encode — Returns the JSON representation of a value ...


2

JSON encoding was introduced in PHP 5.2, WordPress is way older, and it was born (and designed for) PHP 4. Data serialization is a pervasive thing in WordPress, so moving from PHP serialization to JSON encoding would mean a huge backward compatibility problem, and if I know WordPress a little, that will never happen. That said, if you think that JSON ...


2

By get_the_tags() you receive an array of tags attached to the current post. So you could do the following: $tags = get_the_tags(); $tag_ids_to_print = array( 1, 2, 3 ); //List of Tag IDs which you want to be printed $print_tags = array(); if( is_array( $tags ) ){ foreach( $tags as $tag ){ if( in_array( $tag->term_id, $tag_ids_to_print ) ) ...


1

Custom Field Tag filter: You can try the following code snippet to filter tags from a custom field: /** * Support the 'include_tags' custom field (comma seperated tag slugs) * to filter out those tags to display. * * @see http://wordpress.stackexchange.com/a/183929/26350 */ ! is_admin() && add_filter( 'get_the_terms', function( $terms, ...


1

It's not possible, you have to store that value separately, and then you'll be able to use it.


1

I would strongly suggest to seperat the products and not to put them all into one array. Or even to create a taxonomy companies, but this is more up to the while design and maybe a bad idea. Nevertheless this is a nice question to solve, so lets play. So, the 'prefix_products' meta key is always an array of products. Now you need all companies, which sell a ...


1

The underscore prefix are private, these meta fields will be hidden and will not be shown as custom fields in the post backend screens. Those meta fields without the underscore prefix are public fields and shows up as custom fields in the post screens


1

If you would have created your own WP_Query, you could have done it this way: <?php $args = array( 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_key' => 'price' ); $new_query = new WP_Query( $args ); ?> See the examples in the docs: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters ...


1

From what I can tell, this stems from your use of get_post_field(), which is reserved for fields found in the posts table of the database (ie: built-in to WordPress, rather than custom fields). For custom fields you should use get_post_meta().


1

You can also do by this <?php the_post(); if ( is_home() ) { ?> <meta name="description" content="YOUR DESCRIPTION" /> <?php } elseif (is_single()) { ?> <meta name="description" content="<?php the_excerpt(); ?>" /> <?php } ?> this will set different description for home and other.



Only top voted, non community-wiki answers of a minimum length are eligible