Kurzwahl für die Anzeige des Mitarbeiterpostentyps basierend auf dem Standortposttyp und dem Speziellen Beitragstyp

Also habe ich einen ziemlich detaillierten Shortcode mit Attributen, der Staff-Mitglieder basierend auf den Attributen anzeigt, die für Location (Post-Typ) und Specialty (Post-Typ) festgelegt wurden.

Ich habe ein Problem, dass wenn ich zwei Shortcodes auf der gleichen Seite mit verschiedenen Positionen (siehe unten) platziert, zeigt es die Mitarbeiter für die 1. Shortcode perfekt, aber die zweite Shortcode zeigt nicht die Mitarbeiter und zeigt stattdessen die Fallback I ‘ ve codiert.

Ich dachte, ich müsste wp_reset_postdata () verwenden, aber ich wp_query nie einstellen.

Hoffentlich können Sie mich in die richtige Richtung führen. Vielen Dank.

Shortcodes sehen so aus:

  1. [staff_members location = “Carlsbad” Typ = “Arzt” Spezialität = “Notfall / Intensivmedizin”]

  2. [staff_members location = “ontario” type = “Arzt” Spezialität = “Notfall / Intensivmedizin”]

Hier ist mein PHP:

/* ------- List Staff by Location/Type/Specialty/ for Specialty/Location/Staff Pages - Shortcode -------- */ add_shortcode( 'staff_members', 'staff_members_shortcode' ); function staff_members_shortcode( $atts ) { extract( shortcode_atts( array( //Set parameters the shortcode can use 'location' => 'location', 'type' => 'type', 'specialty' => 'specialty', 'style' => 'style' ), $atts )); if( $location ) $location_id = get_page_by_title( $location, OBJECT, 'locations' )->ID; //If location parameter is present use the parameter value to get the ID of the location page of the same name. if( $specialty ) $specialty_id = get_page_by_title( $specialty, OBJECT, 'specialties' )->ID; //If specialty parameter is present use the parameter value to get the ID of the specialty page of the same name. // Set the Meta keys and Orderby parameters for Doctors if ('doctor'==$type) { $meta_keys = array( 'work_title_clause' => array( 'key' => 'work_title', ), 'last_name_clause' => array( 'key' => 'last_name', ), ); $orderby = array( 'work_title_clause' => 'ASC', 'last_name_clause' => 'ASC', ); } // Set the Meta keys and Orderby parameters for Vet Techs if ('vet_tech'==$type) { $meta_keys = array( 'work_title_clause' => array( 'key' => 'work_title', ), 'supervisor_clause' => array( 'key' => 'supervisor', 'type' => 'NUMERIC', ), 'last_name_clause' => array( 'key' => 'last_name', ), ); $orderby = array( 'supervisor_clause' => 'DESC', 'work_title_clause' => 'ASC', 'last_name_clause' => 'ASC', ); } // Set the Meta keys and Orderby parameters for Front Desk if ('front_desk'==$type) { $meta_keys = array( 'work_title_clause' => array( 'key' => 'work_title', ), 'supervisor_clause' => array( 'key' => 'supervisor', 'type' => 'NUMERIC', ), 'last_name_clause' => array( 'key' => 'last_name', ), ); $orderby = array( 'supervisor_clause' => 'DESC', 'work_title_clause' => 'ASC', 'last_name_clause' => 'ASC', ); } // Set the Meta keys and Orderby parameters for Admins if ('admin'==$type) { $meta_keys = array( 'admin_order_clause' => array( 'key' => 'admin_order', 'type' => 'NUMERIC', ), ); $orderby = array( 'admin_order_clause' => 'ASC', ); } /* ------------------------- */ /* Start get_posts() */ /* ------------------------- */ $staff = get_posts(array( 'post_type' => 'staff', 'nopaging' => true, 'meta_query' => array( $meta_keys, 'relation' => 'AND', array( 'key' => 'location', // name of custom field 'value' => $location_id, 'compare' => 'LIKE' ), array( 'key' => 'type', // name of custom field 'value' => $type, 'compare' => 'LIKE' ), array( 'key' => 'specialties', // name of custom field 'value' => $specialty_id, 'compare' => 'LIKE' ), ), 'orderby' => $orderby, )); $locations = get_posts(array( 'post_type' => 'locations', 'nopaging' => true, 'orderby' => 'name', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'specialties', // name of custom field 'value' => $specialty_id, 'compare' => 'LIKE' ), ) )); if( $staff ): { if($style=='style') $style = 'doctor'; foreach ($staff as $staff_member) { $staff_member_id = $staff_member->ID; $thumb_staff = wp_get_attachment_image_src( get_post_thumbnail_id($staff_member_id), 'full' ); //This is the div soup for a single staff member layout $staff_html='
'.get_the_title( $staff_member_id ).'
'.get_field( 'work_title', $staff_member_id ).'
'; // If the Type of Staff post is 'doctor', wrap the query in a link to that doctor's page. // This stops all staff post from being linked since we only want to link doctors. if ( $type == 'doctor' ) $staff_html = ''.$staff_html.''; $return_string.=$staff_html; } } elseif( $locations ): { foreach ($locations as $location) { $location_id = $location->ID; $other_location=''; $return_string.=$other_location; } } elseif( !$locations ): { $return_string='No Doctor or Location is labeled for this Specialty'; } endif; return '
'.$return_string.'
'; } /* --- END SHORTCODE FUNCTIONS FOR DYNAMIC CUSTOM POST TYPE CONTENT --- */

Solutions Collecting From Web of "Kurzwahl für die Anzeige des Mitarbeiterpostentyps basierend auf dem Standortposttyp und dem Speziellen Beitragstyp"