Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_boundary_post [ WordPress Function ]

get_boundary_post ( $in_same_cat = false, $excluded_categories = '', $start = true )
Parameters:
  • (bool) $in_same_cat Optional. Whether returned post should be in a same category.
  • (array|string) $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  • (bool) $start Optional. Whether to retrieve first or last post.
Returns:
  • (object)
Defined at:



Retrieve boundary post.

Boundary being either the first or last post by publish date within the constraints specified by $in_same_cat or $excluded_categories.

Source


<?php
function get_boundary_post$in_same_cat false$excluded_categories ''$start true ) {
    global 
$post;

    if ( empty(
$post) || ! is_single() || is_attachment() )
        return 
null;

    
$cat_array = array();
    if( ! 
is_array$excluded_categories ) )
        
$excluded_categories explode','$excluded_categories );

    if ( 
$in_same_cat || ! empty( $excluded_categories ) ) {
        if ( 
$in_same_cat )
            
$cat_array wp_get_object_terms$post->ID'category', array( 'fields' => 'ids' ) );

        if ( ! empty( 
$excluded_categories ) ) {
            
$excluded_categories array_map'intval'$excluded_categories );
            
$excluded_categories array_diff$excluded_categories$cat_array );

            
$inverse_cats = array();
            foreach ( 
$excluded_categories as $excluded_category )
                
$inverse_cats[] = $excluded_category * -1;
            
$excluded_categories $inverse_cats;
        }
    }

    
$categories implode','array_merge$cat_array$excluded_categories ) );

    
$order $start 'ASC' 'DESC';

    return 
get_posts( array('numberposts' => 1'category' => $categories'order' => $order'update_post_term_cache' => false'update_post_meta_cache' => false) );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics