get_post_custom single array

this is what I’ve done to achieve this, it will return single dimension array when single results are found, and bi-dimensional array when multiple results are found /* * Get post custom Single (in functions.php) */ function get_post_custom_single($post_id) { $metas = get_post_custom($post_id); foreach($metas as $key => $value) { if(sizeof($value) == 1) { $metas[$key] = $value[0]; … Read more

How do I get taxonomy terms by ID in a specific order

get_terms does not support a post__in argument and I don’t see any other argument that will let you force an order. You can, however, accomplish this with one fof at least two filters: function gto_forced_order($orderby) { $orderby = “FIELD(t.term_id,5,1,4)”; return $orderby; } add_filter(‘get_terms_orderby’,’gto_forced_order’); $terms = get_terms(‘category’); var_dump($terms); Or… function gto_forced_order($pieces) { $pieces[‘orderby’] = “ORDER BY … Read more

Generating a random number on every post and saving it in database

I guess you mean something like this: if( function_exists( ‘get_post_random_wpse’ ) ) echo get_post_random_wpse( $post_id = get_the_ID(), $meta_key = ‘_post_random’, $meta_value = rand( 1000, 10000 ) ); where: function get_post_random_wpse( $post_id = 0, $meta_key = ‘_post_random’, $meta_value = 0 ) { if( ! ( $post_id > 0 && strlen( $meta_key ) > 0 ) ) … Read more

How to redirect all pages of a custom post type [duplicate]

As stated by Milo it looks like it a duplicate of [How to disable the single view for a custom post type?] <?php add_action( ‘template_redirect’, ‘subscription_redirect_post’ ); function subscription_redirect_post() { $queried_post_type = get_query_var(‘post_type’); if ( is_single() && ‘subscription’ == $queried_post_type ) { wp_redirect( pricingpageURL, 301 ); exit; } } ?> Just swap our pricingpageURL with … Read more

Is it ok to replace php code with html?

Quite strange that the core developers would decide to make an URL translatable, it is actually a case here of over-doing something. But anyways, lets get to the main question PHP vs HTML Although there are many reasons I can think of why one would prefer PHP above HTML, and that goes for the core … Read more