如何从自定义帖子中获取数组中的值并在我的ajax调用中使用

时间:2013-11-29 07:50:33

标签: php ajax arrays wordpress

//I would like to just pull the value from the array without the key
//this a custom post ant i would like to get the taxonomy in this case series value from the array
 $args = (array( 'post_type' => 'latest_message', 'term' => ''.$terms[0]->name.'','taxonomy' => 'speaker', 'posts_per_page' => 6,'paged' => $paged ));// Blurbs Latest Message
            query_posts( $args );// This is a custom post type loop
              if (have_posts())  : while (have_posts()) : the_post(); 
//this shows up like this Array ( [0] => 28 [1] => 27 [2] => 26 [3] => 25 ) 1 
//I need it to just pull the value so (28, 27,26 25)
            $series = get_terms( 'series', array('fields' => 'ids') );
            $series1= get_the_terms($post->ID,'speaker');
            $termy = get_the_term_list( $post->ID,'speaker');
            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'blurb_image' );
            $image_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'latest_msg' );
                    //This is another attempt at getting that list of id's
            $terms = wp_get_post_terms( $post->ID, 'speaker');?>
            <div class="one-third sermon">
            <?php echo print_r($series);?>
            <h3 class="sermon-title"><?php the_title();?></h3>
                <div class="sermon-holder">
                    <div class="sermon-cont">
                                      //pull in content
                        </div>
            <?php endwhile;  ?>
                  <?php endif; ?>

    if (isset($_POST["series"])) {
            $series = $_POST['series'];
            } else { //This is where i need to pull the values
                 $series = get_terms( 'series', array('fields' => 'ids') );
            }

//我的Ajax页面这是需要为下拉列表提取值的位置。  因此,基本上根据您在下拉列表中的选择,这些值用于从帖子中提取信息

1 个答案:

答案 0 :(得分:0)

你有这个:

$series = get_terms( 'series', array('fields' => 'ids') );
// this is the code that in print_r() shows up like this
Array (
  [0] => 28
  [1] => 27
  [2] => 26
  [3] => 25
) 1

你想要这个吗? (我想是一个字符串)

(28, 27,26 25)

然后试试这个:

$series = get_terms( 'series', array('fields' => 'ids') );
$whatItSeemsYouWant = '('.implode(', ',$series).')';