Tips

Tips is the category that shows on the ‘Tips’ page and the ‘Tips Titles’ page.

Get Tags For Posts In Selected Categories

The code below will return all Terms that are in the taxonomy ‘post_tags’ and are associated with Posts in selected categories.

 

<?php
/* Retrieve all tags from posts in selected categories */

$cats = array('beaches','mountains');  // Must be an array even if only one category
$cats_string = "'" . implode($cats,"','") . "'";
$sql = <<<EOSQL
SELECT DISTINCT t.*
FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id
       AND tt.taxonomy = 'post_tag')
JOIN $wpdb->terms t ON tt.term_id = t.term_id
WHERE
   p.ID IN (
      SELECT p2.ID
      FROM $wpdb->posts p2
      JOIN $wpdb->term_relationships tr2 ON p2.ID = tr2.object_id
      JOIN $wpdb->term_taxonomy tt2 ON (tr2.term_taxonomy_id = tt2.term_taxonomy_id AND tt2.taxonomy = 'category')
      JOIN $wpdb->terms t2 ON (tt2.term_id = t2.term_id AND t2.name IN ($cats_string))
      WHERE p2.post_type = 'post'
      AND p2.post_status = 'publish'
      AND p2.post_date <= NOW()
   )
EOSQL;

$terms = $wpdb->get_results($sql);

// print_r($terms);

echo "<br />";
foreach ($terms as $term) {
   echo "ID:$term->term_id NAME:$term->name SLUG:$term->slug<br />";
}

?>

Migrating A WordPress Site – Step By Step

These instructions are for sites that run Apache servers, either on Linux or XAMPP.  They may work with others, but have not been tested.

Whenever I develop a new site, or need to make extensive changes to an existing site, I like to do the work on a local install and then migrate the site to the live one.  This is a description of the process I use.  As of this writing, this has been used on WP versions 3.1 through 3.9.1.

Continue reading

‘Roll Your Own’ Pagination

In order to provide pagination when query_posts() was used in a non-WP site, the technique shown here was used.

Standard pagination did not work because the ‘paged’ query variable was not set. Instead the ‘pg’ variable was used and added to the links created by previous/next_posts_link(). Continue reading

Form To Calculate Weights On Planets

This article shows the details of a form that calculates the weight on different planets given the weight on earth. It illustrates the following:

  • Coding the form in the HTML mode of the WP editor
  • Using a shortcode to insert the JavaScript that does the calculations
  • The JavaScript itself

Click here to try it out!

Here is a screenshot of the output:

Calculate Planetary Weights screenshot
Continue reading

Select Posts On The First Letter Of A Custom Field

This post is in response to a request to filter posts based on the first letter of a custom field. The requestor was creating a staff listing where the person’s last name was stored in a custom field named ‘staff_last_name’. A menu of all letters was needed to allow the viewer to select the letter to view.

The code shown below should be added into a template that is customized for the theme in use. Continue reading

Ways to Increase Max File Upload Size and Execution TIme

Since I originally posted this, I have assisted several persons with this problem.  One additional thing I have found that will sometimes work is to contact the hosting service support.  A good support group can easily fix this for you.

Here is a list of things that I tried on a couple of my sites to increase the file upload size and the script execution time.

Initial File Upload Size: 2M

Initial Execution Time: 30 sec

The first thing I tried was adding some lines to functions.php.

Note: you must be careful when editing functions.php because any mistakes will cause your site to become unusable and you must use ftp to correct the error.

// Increase max upload file size and execution time
@ini_set( 'upload_max_size' , '20M' );
@ini_set( 'post_max_size', '20M');
@ini_set( 'max_execution_time', '300' );

This did not work.

Next, I tried an addition to wp-config.php.

define('WP_MEMORY_LIMIT', '20M');

Did not work.

I found several reports that adding the following to .htaccess would work:

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value memory_limit 20M
php_value max_execution_time 300

I don’t know if I added the lines incorrectly or not, but it caused internal server errors.

Finally, I created two files, php.ini and php5.ini, with the following lines
and added both files to the wp-admin folder. WORKED!!

upload_max_filesize = 20M
; Maximum size of POST data that PHP will accept.
post_max_size = 20M
max_execution_time = 300

If none of these things work for you, your hosting service support team might increase the limits for you.

Make WordPress More Link Open in a New Window

If you would like your WordPress ‘more’ tag link to open a new window, you can use this filter in your functions.php.

The ‘target=”_blank”‘ method has been deprecated in XHTML, so we are forced to use the onclick and onkeypress methods.


// More tag link open in new window
function more_tag_new_window($link) {
   preg_match('/^(.+)?<a (.*)$/',$link,$matches);
   if ($matches) {
      $link = $matches[1] . '<a '
         . '<a onclick="window.open(this.href); return false;" '
         . 'onkeypress="window.open(this.href); return false;" '
         . preg_replace('/#more-\d+/','',$matches[2]); // Remove the jump link
   }
   return $link;
}
add_filter('the_content_more_link','more_tag_new_window');

Show Latest Post From Each of Specified Categories

The Code below illustrates how to select the latest Post from each of a list of categories.
Continue reading

List Author Information

Several persons have requested code to list information about Post authors. The sample code below illustrates one technique.
Continue reading

WP 3.3.1, TNG 8.1.3 (and 9!), WP TNG Plugin 2.0 WORKING!!!

I recently wanted to set up a WordPress site and use ‘The Next Generation of Genealogy Sitebuilding‘ to create a genealogy page.  After a lot of trial and error, I was able to use the supplied TNG WP Integration plugin (supplied with TNG) to have a Page that showed the TNG pages inside a WP page.

Here is a short description of the steps that were needed:

Continue reading