Anonymous functions usage

Use the second option. Adding anonymous functions as filters and actions is highly discouraged!!! If you add an anonymous function in this fashion, it’s impossible to remove later on down the road by other plugins and code. So please, please, please don’t do that.

wordpress sql posts query won’t display the latest post in a specific category

I’d suggest using the WP_Query() class for this one. Hopefully the below will help you – <?php $args = array( ‘category_name’ => ‘photography’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘posts_per_page’ => 5 ) $work_items = new WP_Query($args); if($work_items->have_posts()) : while($work_items->have_posts()) : $work_items->the_post() echo “<li>”; echo “<a href=”#” onClick=’title_to_contents(“.json_encode(get_the_title()).”)’>”; echo get_the_title(); echo “<span class=”project_date”>”.get_the_time(‘Y’).”https://wordpress.stackexchange.com/”.get_the_time(‘M’).”</span>”; echo “</a>”; … Read more

How to deal with a GET variable of ‘name’?

In case it’s useful for someone else in this situation, I ended up creating a page outside WordPress which renames the ‘name’ parameter (to ‘username’) and then redirects to the page I originally wanted to hit. My code for this external page is: <?php $data = array(‘UID’ => $_GET[‘UID’], ‘username’ => $_GET[‘name’], ‘ANI’ => $_GET[‘ANI’], … Read more

Page load timer?

$starttime is undefined in your footer, so you’re subtracting nothing from endtime. declare global $starttime first and it’ll work. that said, it won’t be a very accurate indicator of rendering time, since most of the work WordPress does happens before you ever reach the template and start your timer. There’s already a built-in timer that … Read more

Pasting this PHP breaks my page. Why?

Make sure you reference the global $wpdb variable first, otherwise PHP doesn’t know what $wpdb is or whether or not it has a get_results() method or a prefix property. So just add global $wpdb; to fix it: <?php global $wpdb; $gallery_ids = $wpdb->get_results( “SELECT gid FROM “.$wpdb->prefix.”ngg_gallery ORDER BY gid ASC”, ARRAY_A); ?>

Create a slug for a page in WordPress

The custom permalink you will most likely want to use is /%postname%/ Which will get the structure that you show above. (mydomain.com/about, mydomain.com/home) If you want to edit the slug, it’s right underneath the title of the post (“Permalink”), click edit.

Defining ‘last’ class on foreach blog posts

Something like this should work for you. $args = array( ‘numberposts’ => 3 ); $lastposts = get_posts( $args ); $count = 1; foreach($lastposts as $post) : setup_postdata($post); ?> <div id=”blog” class=”<?php if ($count == 3) : ?>last<?php endif; ?>”> <div class=”blog-header”><a href=”https://wordpress.stackexchange.com/questions/34591/<?php the_permalink(); ?>”> <?php the_title(); ?> </a> <div class=”date”> <?php the_date(); ?> </div> </div> … Read more