[resolved] please help about post_category (8 posts)

  1. kaankms
    Posted 4 years ago #


    I want to add more than one term_id like

    $articleOption['post_category'] = array(1,2,3,4,5);

    there is a array like

    $arr[0] = "0";
    $arr[1] = "1";
    $arr[2] = "2";

    although the $category output is like 1,2,3, it doesnt work

    $category = implode(",", $arr);
    $articleOption['post_category'] = array($category);

    However it is work;

    $cnt = count($arr);
    	$articleOption['post_category'] = array($arr[0]);
    	$articleOption['post_category'] = array($arr[0],$arr[1]);
    	$articleOption['post_category'] = array($arr[0],$arr[1],$arr[2]);
    	$articleOption['post_category'] = array($arr[0],$arr[1],$arr[2],$arr[3]);
    	$articleOption['post_category'] = array($arr[0],$arr[1],$arr[2],$arr[3],$arr[4]);
    	$articleOption['post_category'] = array($arr[0],$arr[1],$arr[2],$arr[3],$arr[4],$arr[5]);

    So I think it just accept integer one by one.
    How can I get rid of these if conditions ?
    please help me


  2. Mert Yazicioglu
    Posted 4 years ago #

    implode function returns a string, so when you write this:

    $category = implode(",", $arr);
    $articleOption['post_category'] = array($category);

    You are actually assigning array("1,2,3") instead of array(1,2,3). Be careful, the first one has one string element while the other one has three integer elements.

    Since you already have an array filled with the values you want to pass, you should use that one directly:

    $articleOption['post_category'] = $arr;

  3. kaankms
    Posted 4 years ago #

    thank you for your reply however,

    with this code ($category output is like 3,6,4);

    $articleOption['post_category'] = $category;

    there is still error

    Warning: array_filter() expects parameter 1 to be array, string given in C:\Program Files\EasyPHP-5.3.7RC4\www\wordpress\wp-includes\post.php on line 2464
  4. Mert Yazicioglu
    Posted 4 years ago #

    You should not use $category as it is a string created by concatenating elements of the array. You should assign the actual array to $articleOption['post_category'] which is the $arr variable.

    Again, what you should have written is:

    $articleOption['post_category'] = $arr;

  5. kaankms
    Posted 4 years ago #

    mert, it is working now thanks to you.
    Thank you for replies

  6. crisherent
    Posted 4 years ago #

    I'm trying to get the title date and author to show???

    <?php /*
    Template Name: Lucy's Blog
    */ ?>
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'custom_loop');
    function custom_loop() {

    global $paged;
    $args = array('cat' => '995');

    genesis_custom_loop( $args );


    <?php genesis(); ?>

  7. Archana Solanki
    Posted 4 years ago #

    Thanks a lot Mert Yazicioglu.
    That solved my issue also.

  8. nostalgic
    Posted 4 years ago #

    I just wanna ask what's missing or wrong in this :

    I was trying to get the data, if i will use it in the DIV section it works but as a Function it's not.

    please help.

    function custom_dashboard_help() {

    $miles = array();
    $meta_key = 'custom_field_17_subscriptionnumber';//set this to your custom field meta key
    $miles = $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = %s", $meta_key));
    echo 'Total miles is '.array_sum( $miles );


Topic Closed

This topic has been closed to new replies.

About this Topic