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

Foreach displays from last to first

Why wouldn’t you just pull them in the order you need instead of reversing the array? $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, // correct key is posts_per_page, not numberposts ‘orderby’ => ‘date’ ‘order’ => ‘ASC’, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args );

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

Can’t update multiple rows with $wpdb query

$wpdb->query() returns number of rows affected by the query. It’s returning NULL indicates that there is an error in your query. The problem with your query is that you are updating $wpdb->posts table, but the condition depends on $wpdb->postmeta table. You have to join these tables for the query to work. Another problem is that … Read more

How to overwrite orderby with add_query_var

Use pre_get_posts instead.. function my_archive_query_override( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘rand’ ); } } add_action( ‘pre_get_posts’, ‘my_archive_query_override’ ); For that user selectable part, you can use AJAX to accomplish that.