Why do filters/actions require an argument count?

Because of backwards compatibility. You can use the same callback for multiple filters. Inside of that callback you should use current_filter() to determine the context. But some plugins use the number of passed arguments instead. Changing that would break these plugins. That’s why you should always use the API (here: current_filter()) and not some made-up … Read more

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

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

wp_get_attachment_url filter won’t accept two arguments

I think you’re missing the number of callback input arguments, so try this one instead: add_filter( ‘wp_get_attachment_url’,’mfeu_filter_attachment_url’, 10, 2 ); | | Priority _____| | Number of arguments ________| The default is 10, 1, so you’re currently only passing on the $url and not the second $post_id argument.