Trying to get property of non-object when using $post->post_parent

@kaiser answer gives you the solution. I see from your comment that you don’t understand, so I upvoted his answer and translate it in code: <?php $bannerimg = ‘home.jpg’; $post = is_singular() ? get_queried_object() : false; if ( ! empty($post) && is_a($post, ‘WP_Post’) ) { if ( ‘about’ == $post->post_name || ‘2’ == $post->post_parent ) … Read more

Get post id by attachment id?

get_post_ancestors can give you the ID of the object an attachment is associated with: $attachment_id = 42; $parent = get_post_ancestors( $attachment_id ); echo $parent[0]; // $parent will be an array

Create an “All Posts” or “Archives” Page with WordPress 3.0?

Create a new template file and do this as the loop: query_posts( array( ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’ ) ); if( have_posts() ): echo ‘<ul>’; while( have_posts() ): the_post(); echo ‘<li><a href=”‘; the_permalink(); echo ‘”>’; the_title(); echo ‘</a></li>’; endwhile; echo ‘</ul>’; endif; wp_reset_query(); Then just use that template for a page and it’ll automatically … Read more

Adding a div class or id inside the_content()

You have to put your advertisement block just before <?php the_content(); ?> in a separate div-layer and add some css to it. E.g. single.php <div class=”entry entry-content”> <div class=”advertisement”> <p>Your advertisement</p> </div> <?php the_content(); ?> </div> CSS div.advertisement { float: left; width: 150px; padding: 0px 10px 10px 0px; }

Display all search results

The quick and dirty way to do it would be to use query_posts again, doubling the number of database calls. <?php if (have_posts()) : ?> <?php query_posts(‘showposts=999’); ?> Better would be to add this to functions.php, altering the original query before it is executed: function change_wp_search_size($query) { if ( $query->is_search ) // Make sure it … Read more

How to display posts by current user/author in a custom page template?

this should work for you: if ( is_user_logged_in() ): global $current_user; wp_get_current_user(); $author_query = array(‘posts_per_page’ => ‘-1′,’author’ => $current_user->ID); $author_posts = new WP_Query($author_query); while($author_posts->have_posts()) : $author_posts->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/23829/<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a> <?php endwhile; else : echo “not logged in”; endif;

Group Posts by First Letter of Title

once up a time i did a client project where i had to have archives by first letter. thinking back i’m wondering if shouldn’t have just created a hidden taxonomy and then saved the first letter as a term in that taxonomy. anyway, here’s what i actually did: /* * Function Create Array of Letters … Read more

Manually delete post from database

Drop this into a file in your plugin directory and you should be able to do this from your WP installation using a query string. /* Plugin Name: Delete Specific Post Description: Rid the post forever! Version: 0.1 Author: WPSE License: GPL2 */ add_filter(‘query_vars’, ‘delete_post_query_var’); function delete_post_query_var($vars){ $vars[] = ‘delete_post’; return $vars; } add_action(‘admin_init’, ‘manually_delete_post’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)