Changeset 11278 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
- Timestamp:
- 10/14/2021 12:08:48 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r11275 r11278 412 412 'duration' => 'duration', 413 413 'level' => 'level', 414 'series' => 'wporg_workshop_series',415 414 'topic' => 'topic', 416 415 'type' => 'instruction_type', 417 416 ); 417 418 $series_slug = wporg_learn_get_series_taxonomy_slug( $query->get( 'post_type' ) ); 419 if ( $series_slug ) { 420 $entity_map['series'] = $series_slug; 421 } 418 422 419 423 $meta_query = array(); … … 771 775 772 776 /** 773 * Get the series taxonomy term object for a workshop post. 774 * 775 * @param int|WP_Post|null $workshop 777 * Get the slug for the series taxonomy for a given post type. 778 * 779 * @param string $post_type 780 * 781 * @return false|string 782 */ 783 function wporg_learn_get_series_taxonomy_slug( $post_type ) { 784 $tax_slug = false; 785 786 switch ( $post_type ) { 787 case 'lesson-plan': 788 $tax_slug = 'wporg_lesson_plan_series'; 789 break; 790 case 'wporg_workshop': 791 $tax_slug = 'wporg_workshop_series'; 792 break; 793 } 794 795 return $tax_slug; 796 } 797 798 /** 799 * Get the series taxonomy term object for a post. 800 * 801 * @param int|WP_Post|null $post 776 802 * 777 803 * @return WP_Term|bool 778 804 */ 779 function wporg_ workshop_series_get_term( $workshop= null ) {780 $ workshop = get_post( $workshop);781 782 if ( ! $ workshopinstanceof WP_Post ) {805 function wporg_learn_series_get_term( $post = null ) { 806 $post = get_post( $post ); 807 808 if ( ! $post instanceof WP_Post ) { 783 809 return false; 784 810 } 785 811 786 $terms = wp_get_post_terms( $workshop->ID, 'wporg_workshop_series' ); 812 $tax_slug = wporg_learn_get_series_taxonomy_slug( get_post_type( $post ) ); 813 $terms = wp_get_post_terms( $post->ID, $tax_slug ); 787 814 788 815 if ( empty( $terms ) ) { … … 794 821 795 822 /** 796 * Given a workshop post in a series, get all the workshopposts in the series.797 * 798 * @param int|WP_Post|null $ workshop823 * Given a post in a series, get all the posts in the series. 824 * 825 * @param int|WP_Post|null $post 799 826 * 800 827 * @return WP_Post[] 801 828 */ 802 function wporg_workshop_series_get_siblings( $workshop = null ) { 803 $term = wporg_workshop_series_get_term( $workshop ); 829 function wporg_learn_series_get_siblings( $post = null ) { 830 $post_type = get_post_type( $post ); 831 $term = wporg_learn_series_get_term( $post ); 804 832 805 833 if ( ! $term ) { … … 808 836 809 837 $args = array( 810 'post_type' => 'wporg_workshop',838 'post_type' => $post_type, 811 839 'post_status' => 'publish', 812 840 'posts_per_page' => 999, … … 814 842 'tax_query' => array( 815 843 array( 816 'taxonomy' => 'wporg_workshop_series',844 'taxonomy' => wporg_learn_get_series_taxonomy_slug( $post_type ), 817 845 'terms' => $term->term_id, 818 846 ), … … 824 852 825 853 /** 826 * Given a workshop post in a series, get an adjacent workshop post in theseries.854 * Given a post in a series, get an adjacent post in that series. 827 855 * 828 856 * @param string $which Which adjacent post to retrieve. 'previous' or 'next'. 829 * @param int|WP_Post|null $ workshop857 * @param int|WP_Post|null $post 830 858 * 831 859 * @return WP_Post|bool 832 860 */ 833 function wporg_ workshop_series_get_adjacent( $which, $workshop= null ) {834 if ( ! $ workshopinstanceof WP_Post ) {835 $ workshop = get_post( $workshop);836 } 837 838 $siblings = wporg_ workshop_series_get_siblings( $workshop);861 function wporg_learn_series_get_adjacent( $which, $post = null ) { 862 if ( ! $post instanceof WP_Post ) { 863 $post = get_post( $post ); 864 } 865 866 $siblings = wporg_learn_series_get_siblings( $post ); 839 867 $sibling_ids = wp_list_pluck( $siblings, 'ID' ); 840 $index = array_search( $ workshop->ID, $sibling_ids, true );868 $index = array_search( $post->ID, $sibling_ids, true ); 841 869 842 870 if ( false === $index ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)