WordPress.org

Ready to get started?Download WordPress

Forums

List category posts
[resolved] Custom taxonomy support and array get_posts call (3 posts)

  1. wsherliker
    Member
    Posted 2 years ago #

    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/

  2. picandocodigo
    Member
    Plugin Author

    Posted 2 years ago #

    Hey thanks for using the plugin AND special thanks for this code. I've added it into version 0.19.

    Regards!

    Fernando

  3. jankowalski
    Member
    Posted 2 years ago #

    i don t find lcp_set_categories function CatList.php file, taxonomy is not working either...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic