db converts decimal number wrong

Within $wpdb->insert, you are using %d which is used to store integer, use %f instead which will store float/decimal values. $registrering = $wpdb->insert( $wpdb->prefix . ‘registreringer’, array( ‘fiske_vaegt’ => $fiske_vaegt ), array( ‘%f’ ) );

get_the_title() gets printed out twice

Your conditional is always true. To understand why, consider what happens in this function when there is no post parent: function get_top_ancestor_id() { global $post; // no parent so this doesn’t run: // if($post->post_parent) { // $ancestors = array_reverse(get_post_ancestors($post->ID)); // return $ancestors[0]; // } return $post->ID; } Which simplifies to: function get_top_ancestor_id() { global $post; … Read more

Shortcode to show the code

get_footer() echos the contents of the footer.php file. add_shortcode() requires that the callback return the contents of the shortcode and not echo it. I suppose you could do something like this if you really want. function show_footer() { ob_start(); get_footer(); return ob_get_clean(); } add_shortcode( ‘show_f’, ‘show_footer’ );

How can this crude function be improved?

function admin_trim_category_description( $terms, $taxonomies ){ if( ‘category’ != $taxonomies[0] )return $terms; $whatever_categories = array(‘category1’, ‘hidden’, ‘category2’, ‘category3’); foreach( $terms as $key => $term) if(!in_array($terms[$key]->name, $whatever_categories)) $terms[$key]->description = strip_tags(substr( $term->description, 0, 75 )).”…”; else unset($terms[$key]); return $terms; }

WordPress theme options error

First, change your code into the following: $value = get_option( ‘mytheme_value’ ); query_posts ( “meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value={$value}”); When you use single quotation marks, php isn’t parsed in the string, and functions (like get_option) will never be called from within a string. Therefore, call the function get_option first, and put the value in a double quoted string (which … Read more

Change WordPress Upload Folder using wp handle upload

Don’t store user uploads in your theme folder! I would suggest you store them in a sub-directory of the default uploads folder. You can use the upload_dir filter to temporarily change the path: function wpse_183245_upload_dir( $dirs ) { $dirs[‘subdir’] = ‘/abc’; $dirs[‘path’] = $dirs[‘basedir’] . ‘/abc’; $dirs[‘url’] = $dirs[‘baseurl’] . ‘/abc’; return $dirs; } And … Read more