Adding a span when custom post type is updated

No, you’re right. This is the code that is responsible for ‘New’ span: <?php if (strtotime($post->post_date) > strtotime(‘-14 days’)): ?> <div class=”new-job-tag”><span>New</span></div> <?php endif; ?> The only problem with your modification is that there is no field called the_modified_date in WP_Post object. The proper name of that field is post_modified, so your code should look … Read more

How to display related posts from parent category

Just change this one line: $cat_obj = $wp_query->get_queried_object(); $thiscat_id = $cat_obj->term_id; $thiscat = get_category($thiscat_id); $chi = array(); if (!empty($thiscat->parent)) { $parentcat = get_category($thiscat->parent); $categories_chi=get_categories( array( ‘parent’ => $parentcat->cat_ID ) ); foreach ($categories_chi as $key => $value) { $chi[] = $value->cat_ID; } $pare = array($parentcat->term_id); $ids = array_merge($pare, $chi); } else { $ids = array($cat_obj->term_id); } … Read more

Image upload via FTP to wordpress media library

You can upload your images to your host, and then use media_sideload_image() to upload each file. Let’s assume you upload all of your images to a folder named wpse, in the root of your WordPress installation: // Set the directory $dir = ABSPATH .’/wpse’; // Define the file type $images = glob($directory . “*.jpg”); // … Read more

Replacing the NavWalker dropdown element

You need to replace the end_lvl method of Walker_Nav_Menu as well. This is what you would need to add: public function end_lvl( &$output, $depth = 0, $args = array() ) { if ( isset( $args->item_spacing ) && ‘discard’ === $args->item_spacing ) { $t=””; $n = ”; } else { $t = “\t”; $n = “\n”; … Read more

How to tell if $query_var isset?

use the indentical comparison operator: if(get_query_var(‘cls’) !== ” && get_query_var(‘ch’) !== ”) { mcs_textbook_chapter($dialect, $cls, $ch); } elseif(get_query_var(‘cls’) !== ”) { mcs_textbook_chapter($dialect, $cls); } else { mcs_textbook($dialect); }

Automatic Excerpt Not Working

It turns out my client added shortcodes to the beginning of the posts and the only thing I can think of is that the_excerpt was choosing what words to use from the content before stripping shortcode tags out, thus, returning a blank excerpt. Hope this helps someone in the future

WordPress Customizer not setting default value upon initial install?

I’ve managed to fix this by changing the operator on the ‘if’ statement: Original: ?> <style type=”text/css”> <?php if( get_theme_mod( ‘facebooklink_edit’ ) == ” ) { ?> #fb-footer-bg { display: none; } <?php } // end if ?> </style> <?php Updated: ?> <style type=”text/css”> <?php if( get_theme_mod( ‘facebooklink_edit’ ) === #fb-footer-bg { display: none; } … Read more

How can I programmatically save data into custom fields that contain serialized data?

For serializing and unserializing Data in WordPress, you can use maybe_unserialize and maybe_serialize. If you want to handle the data and add/change values, you could use something like this: $metaarray = maybe_unserialize(get_post_meta($post_id,’_ait-dir-item’,TRUE)); //now $metaarray has an array, if it is serialized. If not, $metaarray has a string. if(is_array($metaarray)){ $metaarray[‘mynewfield’] = ‘Some text i need to … Read more

Insert After Second Paragraph Without Tag?

I need to stress that I think this is going to be very unstable and you may not always get the results you want, but in simple cases this should work. $content = apply_filters(‘the_content’, get_the_content()); $content = explode(“</p>”, $content, 2); // var_dump($content); // debug echo $content[0].'</p>’; echo ‘<div>Extra Content</div>’; if (!empty($content[1])) { echo $content[1]; }