0

I'm trying the following (it's a sidebar widget in the Single New template):

  <ul class="featured-jobs">
  <?php
    $postid = $post->ID;
    $categories = get_the_category($post->ID);
  ?>
  <h2><?php echo $postid; ?></h2>
  <h2><?php echo $categories; ?></h2>
  <?php // Create and run custom loop
    $args=array(
      'post_type' => 'news',
      'category__in' => $categories,
      'post__not_in' => $postid,
      'posts_per_page'=> 3 // Number of related posts that will be shown.
    );
    $custom_posts = new WP_Query();
    $custom_posts->query( $args );
    while ($custom_posts->have_posts()) : $custom_posts->the_post();
  ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  <?php endwhile; ?>
  <?php wp_reset_postdata(); ?>
  <li class="see-all-positions"><a href="http://www.pixelmatic.com/open-jobs/">See All Positions >></a></li>
  </ul>

But as it turns out, $postid comes up blank and $categories outputs as Array.

What am I doing wrong here?

0

Try using $wp_query global variable:

global $wp_query;
$postid = $wp_query->post->ID;
0
$_post = get_queried_object();
$post_id = $_post->ID;

It's somehow like that how single_post_title() gets the title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.