Get Post’s first image using Short-code

I would rewrite a simple shortcode to retrieve only post images: add_shortcode( “postImages”, “stack_309224_attachhment” ); function stack_309224_attachhment($atts){ extract(shortcode_atts( array( ‘id’ => 1, // default id of the post “max” =>4 ,// default max number of images to display “featured”=>”false” // if to retrieve the post featured image or not, default false ), $atts )); ob_start(); … Read more

How to create wordpress class with post meta? [closed]

Can you try this. This should work. You don’t need to use construct if you call getDatain your theme files. You key need to be static value. After that you can call it like self::$key Use like this : echo $theme->getData(get_the_ID()); inform me if code works 🙂 <?php class themeSettings { private static $key= ‘themeSettings’; … Read more

Show post content and title in diferent divs using WP_Query using a loop

PHP loops are loops – you can control them 😉 <?php $the_query = new WP_Query( array(‘posts_per_page’ => 4) ); if ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class=”grid”> <div class=”main post”> <!–show data of the first post in the array–> <?php the_title(); ?> <?php the_content(); ?> </div> <div class=”nested”> <?php while ( $the_query->have_posts() ) : … Read more

Delete all drafts?

draft is not a post_type, it’s a post_status. So you should use your second block of code with that substitution: DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_status=”draft”

How To capitalize The First Letter Of Every Word In The Post Title

The code below was assembled of different pieces I’ve found around and it was not tested. Consider it as an idea only. <?php add_filter( ‘the_title’, ‘my_capitalize_title’, 10, 2 ); function my_capitalize_title( $title, $id ) { // get separate words $words = preg_split( ‘/[^\w]*([\s]+[^\w]*|$)/’, $title, NULL, PREG_SPLIT_NO_EMPTY ); $stop_words = array( ‘the’, // ‘a’, ‘and’, ‘of’, … Read more

Disable WordPress Archive Conflict Check

If you read a little further down past that code you are thinking about commenting out, you will see that right before the function is finished it provides a hook for the result: return apply_filters( ‘wp_unique_post_slug’, $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ); This means you can override what it is doing to your slugs: … Read more