WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: List category posts] Custom taxonomy support and array get_posts call

[Resolved] [Plugin: List category posts] Custom taxonomy support and array get_posts call

  • Below is a patch to add support for custom taxonomies and also move to the array call of get_posts (also needed for the custom taxonomy support).

    list_cat_posts.php add:
    ,’taxonomy’ => ” // Added for custom taxonomy support
    to the end of the $atts = shortcode_atts(array(… statement

    CatList.php function lcp_set_categories rewritten to use array get_posts call and added custom taxonomy support. Note: Old code is included below for reference but commented out:

    /**
    * Get the categories & posts
    */
    private function lcp_set_categories(){
    if($this->params[‘name’] != ” && $this->params[‘id’] == ‘0’){
    $this->lcp_category_id = $this->get_category_id_by_name($this->params[‘name’]);
    }else{
    $this->lcp_category_id = $this->params[‘id’];
    }

    //$lcp_category = ‘cat=’ . $this->lcp_category_id;
    $args = array(‘cat’ => $this->lcp_category_id);

    //Build the query for get_posts()
    /*$lcp_query = $lcp_category.’&numberposts=’ . $this->params[‘numberposts’] .
    ‘&orderby=’ . $this->params[‘orderby’] .
    ‘&order=’ . $this->params[‘order’] .
    ‘&exclude=’ . $this->params[‘excludeposts’] .
    ‘&tag=’ . $this->params[‘tags’] .
    ‘&offset=’ . $this->params[‘offset’];*/
    $args = array_merge($args, array(
    ‘numberposts’ => $this->params[‘numberposts’],
    ‘orderby’ => $this->params[‘orderby’],
    ‘order’ => $this->params[‘order’],
    ‘exclude’ => $this->params[‘excludeposts’],
    ‘offset’ => $this->params[‘offset’]
    ));

    // Post type and post parent:
    /*if($this->params[‘post_type’]): $lcp_query .= ‘&post_type=’ . $this->params[‘post_type’]; endif;
    if($this->params[‘post_parent’]): $lcp_query .= ‘&post_parent=’ . $this->params[‘post_parent’]; endif;*/
    if($this->params[‘post_type’]): $args[‘post_type’] = $this->params[‘post_type’]; endif;
    if($this->params[‘post_parent’]): $args[‘post_parent’] = $this->params[‘post_parent’]; endif;

    // Custom fields ‘customfield_name’ & ‘customfield_value’ should both be defined
    if($this->params[‘customfield_name’] != ” && $this->params[‘customfield_value’] != ”):
    //$lcp_query .= ‘&meta_key=’ . $this->params[‘customfield_name’] . ‘&meta_value=’ . $this->params[‘customfield_value’];
    $args[‘meta_key’] = $this->params[‘customfield_name’];
    $args[‘meta_value’] = $this->params[‘customfield_value’];
    endif;

    // Added custom taxonomy support
    if ($this->params[‘taxonomy’] != “” && $this->params[‘tags’] != “”) {
    $args[‘tax_query’] = array(array(
    ‘taxonomy’ => ‘topic-tag’,
    ‘field’ => ‘slug’,
    ‘terms’ => explode(“,”,$this->params[‘tags’])
    ));
    } elseif ($this->params[‘tags’] != “”) {
    $args[‘tag’] = $this->params[‘tags’];
    }

    //$this->lcp_categories_posts = get_posts($lcp_query);
    $this->lcp_categories_posts = get_posts($args);
    }

    Hope it helps some people out there. Would think we should move list category posts to an array call anyway as this is the easier to understand/more modern system.

    Great plugin though – use it on loads of sites. Cheers

    W.

    http://wordpress.org/extend/plugins/list-category-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: List category posts] Custom taxonomy support and array get_posts call’ is closed to new replies.