Hot answers tagged

3

Your problem is your custom query. Do not use variables that is used by default by Wordpress. $posts and $post is Wordpress reserved global variables. Change $post to a unique variable, something like $posts_query. When using get_posts and you need to setup postdata to make use of template tags, you have no choiche but to use $post as setup_postdata() ...


3

You need to get the post ids from the original main query and exclude them. Then you should remove your offset from your custom query. That should do the trick. Random ordering basically ignores the offset parameter, so you need to explicitely remove the posts from the query to exclude them You can use wp_list_pluck() to get an array of post ids from the ...


3

I believe that you can achieve this effect by grouping the query by author ID, which will require a filter(mostly cribbed from the Codex): function my_posts_groupby($groupby) { global $wpdb; $groupby = "{$wpdb->posts}.post_author"; return $groupby; } add_filter( 'posts_groupby', 'my_posts_groupby' ); If you have less than 8 authors, ...


1

This is a default feature which by default is set not to show the post date. Here is the part of the code responsible to show/hide the post date <?php if ( $show_date ) : ?> <span class="post-date"><?php echo get_the_date(); ?></span> <?php endif; ?> To enable the post date, just check the Display post date? checkbox ...


1

I'm not sure what you're doing with the above script, but here are some random suggestions: Avoid using the root user, for security reasons create another database user with less powers. Avoid using deprecated mysql_* calls. Use WP_Query() or get_posts() instead of hardcoded SQL queries. Use global $wpdb object if you really must use hardcoded SQL ...


1

HERE IS THE SOLUTION /** * Extend Recent Posts Widget * * Adds different formatting to the default WordPress Recent Posts Widget */ Class My_Recent_Posts_Widget extends WP_Widget_Recent_Posts { function widget($args, $instance) { if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; ...


1

If you want both posts that have and do not have a meta key, you need an OR relation meta query to select both posts with key and those where it does not exist. $args = array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => '_post_like_count', 'compare' => 'EXISTS' ), array( ...


1

You can do it easily with WP_Query: $args = array( 'date_query' => array( 'relation' => 'OR', array( 'column' => 'post_date', 'after' => '-2 days' ), array( 'column' => 'post_modified', 'after' => '-2 days' ) ) ); $query = new WP_Query( ...


1

get_the_content() returns unfiltered content, and using a shortcode you cannot use the_content() to return filtered content as you cannot echo inside a shortcode. Your best option here will be is to applying the_content filters to get_the_content(), something like: apply_filters( 'the_content', get_the_content() ); EDIT Exact usage, replace $output .= ...



Only top voted, non community-wiki answers of a minimum length are eligible