Update postmeta after theme switch

I am going to guess that you have your code in the theme, probably functions.php. That code will only load when the theme is active, and after_switch_theme only runs after the theme change. There is no before_switch_theme that I am aware of. You will need to have this code in a plugin or a mu-plugin … Read more

Exclude specific post from displaying

Post__not_in doesn’t need the minus or the ‘ ‘ Make it an array like this: ‘post__not_in’ => array(4135), Try adding the post ID into a variable e.g. $excludes = array(‘4135’); ‘post__not_in’ => $excludes

Function won’t run onclick using Ajax

1) Is your function working? First do a console.log( “it’s working” ); inside your function and check it on your browser’s console. If it’s not showing when you click, you must refactor your function. 2) Have you defined ajaxurl? Unlike on the admin side, the ajaxurl javascript global does not get automatically defined for you, … Read more

How to sent a email outside WordPress?

If you are outside WordPress and want to load Wordpess, you only need: require (‘/path/to/wp-load.php’); In some situations you may want to load only some WordPress functions, for example: define(‘SHORTINIT’, true); require (‘/path/to/wp-load.php’); require( ABSPATH . WPINC . ‘/formatting.php’ ); require( ABSPATH . WPINC . ‘/meta.php’ ); require( ABSPATH . WPINC . ‘/post.php’ ); //Load … Read more

Capitalize Shortcode Value on Output

Try this out. . . function cwc_pkmn( $atts = array(), $content=”” ) { // ———————— // Settings: $path=”https://wordpress.stackexchange.com/path/to/file/”; $ext=”png”; // ———————— // Shortcode input: $atts = shortcode_atts( array( ‘name’ => ” ), $atts, ‘pkmn_shortcode’ ); // Sanitize input: $name = esc_attr( $atts[‘name’] ); // Init: $words_ucfirst = array(); // Capitalize the first letter in each … Read more

Using Shortcode to Grab Archive Listing, Separate by Year

I found this answer: http://www.stemlegal.com/strategyblog/2011/wordpress-wednesdays-better-archive-lists-in-wordpress/ And the final code looks something like this: function getarchives_filter($where, $args) { if (isset($args[‘year’])) { $where .= ‘ AND YEAR(post_date) = ‘ . intval($args[‘year’]); } return $where; } add_filter(‘getarchives_where’, ‘getarchives_filter’, 10, 2); function my_archives($params, $content = null) { extract(shortcode_atts(array( ‘type’ => ‘style1’ ), $params)); $currentyear = date(‘Y’); $years = range(‘2012’,$currentyear); … Read more

Do I have anything to worry about when switching to a default theme to test for plugin conflictions?

In a nutshell it is going to affect things, which has configuration specific to the current theme. Out of native functionality that would be most prominently: menus (which are assigned to theme locations) widgets (which are assigned to sidebars) This can go further if theme provides sidebars and custom widgets for example. Overall there are … Read more

What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?

A custom template for one specific category should be named category-slug.php where “slug” is the WP slug for the category. WordPress will automatically use this file to display the archive for that one category. You could also name it using the ID of the category. If your category is “legacy-posts”, then your template file should … Read more

Get latest post from all categories except one

Your code doesn’t make sense to me. The easiest way to do this is to use get_categories() to get all the categories, and use the exclude parameter to exclude the category that you don’t need. You can then feed that back into a new WP_QUERY Example $categories = get_categories( ‘exclude=ID_OF_CATEGORY’) foreach ($categories as $category) { … Read more