Remove posts after a given amount of time

You can use wp_delete_post() and get_the_date(). global $wpdb; if ( !is_user_logged_in()) echo ‘You must be logged in.’; // check if title $my_post_name already exists in wpdb else if ( is_user_logged_in()&& $wpdb->get_row(“SELECT post_title FROM wp_posts WHERE post_title=”” . $my_post_name . “””, ‘ARRAY_A’)) { // then check age of the post? assign age to a variable? $time … Read more

How does the ternary operator work in the wordpress loop post?

The double colon in this case is part of the alternative syntax for control structures. That’s not the ternary operator. You could also write instead: if ( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } I prefer the second style, most code editors enable automatic folding with it, so I can close … Read more

How to create a custom category of wordpress admin

You might consider the idea of creating a custom post type called ticker. On the custom post type, add a custom field (input field) and store it as the value. Then one option would be to use code of this nature in your homepage template: <?php $args = array(     ‘numberposts’     => 5, // how many posts will be in the … Read more

Echo URL of large version of Featured Image

Use the second parameter of wp_get_attachment_image_src(): $size. $att = wp_get_attachment_image_src( $att_ID, ‘large-thumb’ ); or $att = wp_get_attachment_image_src( $att_ID, array ( 900, 300 ) ); The size is passed to image_downsize() and there to image_get_intermediate_size(). If $size is an array WordPress will search for the best match in existing images: // from wp-includes/media.php::image_get_intermediate_size() // get the … Read more

Accessing site’s root from themes folder

I guess you’re talking about a site specific wp-config.php file that resides in your themes folder. At the point where you’re loading the wp-config.php file, WP isn’t fully loaded, so you ain’t got any constants or filesystem API or other basic API functions available. Here’s how I approach this: Structure # Dir structure ~/ROOT ├── … Read more

Set WordPress Default Template

The better, cleaner solution would be not to use custom page templates to define page layouts*, but rather to use custom post meta to define page layouts. To implement: Create a Theme Option for Default static page layout, that includes all possible page layout options Create a _page_layout custom post meta for Page Layout, that … Read more

Single.php back button to parent category

You can use get_the_category() and return the first result as in the example. Technically you could have several parent categories so you need to deal with this separately or expect that the first element of the array is always the right parent category.