Use Author Ids or Names to echo different output inside loop
<?php if (get_the_author_meta(‘ID’) == 7) : ?> Do something for user with ID 7. <?php else : ?> Do something for anybody else. <?php endif; ?> Try this, where 7 is the ID of the user.
<?php if (get_the_author_meta(‘ID’) == 7) : ?> Do something for user with ID 7. <?php else : ?> Do something for anybody else. <?php endif; ?> Try this, where 7 is the ID of the user.
do you have a query pulling those related posts at the bottom? the 4 squares? it looks like you need a wp_reset_query() after those as the final square is titled “prova 3” which is the post you are showing the object data for in the sidebar.
<?php $recent_comments = get_comments( array( ‘number’ => 1, ‘status’ => ‘approve’ ) ); foreach($recent_comments as $comment) : $latest_postid_with_comment = $comment->comment_post_ID; endforeach; ?> Probably way to compress this code into something smaller. But this will work.
if you set the fields parameter to ids you will get an array of ids instead of unneeded post data ex: $ongoing_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_ongoingPromotion’, ‘meta_value’ => 1, ‘fields’ => ‘ids’ ); $current_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_endDate’, ‘meta_value’ => date(“Y/m/d”), ‘meta_compare’ => ‘>=’, ‘orderby’ => ‘meta_value’, … Read more
The correct way: $my_query = new WP_Query(‘posts_per_page=2′); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php global $post; print_r($post); // <– this is your postStuff ?> <?php endwhile;?> <?php wp_reset_query(); ?> Normally, you dont’t need to globalize the post. There are helper functions that should be used instead to fetch information from the current post
You could hook into ‘attachment_fields_to_edit’ and just add a row: <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Show Attachment ID * Version: 2012.06.04 * Author: Thomas Scholz <[email protected]> * Author URI: http://toscho.de * License: MIT * License URI: http://www.opensource.org/licenses/mit-license.php */ if ( ! function_exists( ‘t5_show_attachment_id’ ) ) { add_filter( ‘attachment_fields_to_edit’, ‘t5_show_attachment_id’, … Read more
Short of building it yourself, you don’t. WordPress doesn’t have a way to get a nested array of comments like that. Instead, it gets all the comments to be displayed, then uses a class called a “walker” to display them. The Walker_Comment class is built on top of the generic Walker class. The Walker class … Read more
I have just found an alternative solution: global $post; $current_post = $post->ID; $array=range(1,$current_post); $args = array( “numberposts’ => 5, ‘offset’ => 0, ‘category’ => $category->term_id, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘exclude’ => $current_post, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true, ‘post__in’ => $array ); $posts = get_posts($args); I’m not sure why the … Read more
You don’t have to determine what type it is to query it, you just have to set the proper arguments to override defaults. First off, we’ll use WP_Query to do additional queries instead of query_posts. If we only set the p argument, post_type defaults to post, so we won’t get any pages: $query = new … Read more
see documentation for get_field. change: $attachment_id = get_field(‘image’); to pass the post ID as second argument: $attachment_id = get_field(‘image’, 299); or: $attachment_id = get_field(‘image’, $my_id);