• I am using WordPress as my CMS and i’m trying to create a page where users can find a list of articles in a category. I’m basically using a modified version of the WP Classic theme and using the arc-cont.php file as the basis for my page template. I’m putting the category number that i want into a custom field and trying to use that as the variable. I keep getting an “Array” message when i put the code in, and i can’t figure out how to get it to just list the posts that i want.

    Below is the code for the entire template.

    <?php
    /*
    Template Name: Archives with Content
    */
    ?>
    
    <?php
    get_header();
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    	 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    	<div class="meta"><?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php edit_post_link(__('Edit This')); ?></div>
    
    	<div class="storycontent">
    		<?php the_content(__('(more...)')); ?>
    	</div>
    
    </div>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php posts_nav_link(' — ', __('&laquo; Older Posts'), __('Newer Posts &raquo;')); ?>
    
    </div> <// End page content, begin listing archives>
    <div id="content" class="widecolumn">
    <?php
    
          $mykey_values = get_post_custom_values( $key = 'category', $value, $single = true );
          foreach ( $mykey_values as $value ) {
          echo "$key => $value (category=$mykey_values)<br />";
              }
    
    ?>
    <div id="main">
    <h2>Posts relating to this subject:</h2>
        <ul>
            <?php $posts = get_posts('category=$mykey_values');
    
            if( $posts ) : 
    
            foreach( $posts as $post ) : setup_postdata( $post ); ?>
    
            <li><a href="<?php the_permalink(); ?>" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    
            <?php endforeach; ?>
    
    		<?php endif; ?>
        </ul>
    </div>
    <?php get_footer(); ?>

  • The topic ‘Can’t stop getting an array when using the $single function’ is closed to new replies.