Changeset 1057 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
- Timestamp:
- 12/19/2014 09:57:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
r1054 r1057 1104 1104 } 1105 1105 1106 /** 1107 * Retrieve an explanation for the given post. 1108 * 1109 * @param int|WP_Post $post Post ID or WP_Post object. 1110 * @param bool $published Optional. Whether to only retrieve the explanation if it's published. 1111 * Default false. 1112 * @return WP_Post|null WP_Post object for the Explanation, null otherwise. 1113 */ 1114 function get_explanation( $post, $published = false ) { 1115 if ( ! $post = get_post( $post ) ) { 1116 return null; 1117 } 1118 1119 $args = array( 1120 'post_type' => 'wporg_explanations', 1121 'post_parent' => $post->ID, 1122 'no_found_rows' => true, 1123 'posts_per_page' => 1, 1124 ); 1125 1126 if ( true === $published ) { 1127 $args['post_status'] = 'publish'; 1128 } 1129 1130 $explanation = get_children( $args, OBJECT ); 1131 1132 if ( empty( $explanation ) ) { 1133 return null; 1134 } 1135 1136 $explanation = reset( $explanation ); 1137 1138 if ( ! $explanation ) { 1139 return null; 1140 } 1141 return $explanation; 1142 } 1143 1144 /** 1145 * Retrieve data from an explanation post field. 1146 * 1147 * Works only for published explanations. 1148 * 1149 * @see get_post_field() 1150 * 1151 * @param string $field Post field name. 1152 * @param int|WP_Post $post Post ID or object for the function, hook, class, or method post 1153 * to retrieve an explanation field for. 1154 * @param string $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db', 1155 * or 'display'. Default 'display'. 1156 * @return string The value of the post field on success, empty string on failure. 1157 */ 1158 function get_explanation_field( $field, $post, $context = 'display' ) { 1159 if ( ! $explanation = get_explanation( $post, $published = true ) ) { 1160 return ''; 1161 } 1162 return get_post_field( $field, $explanation, $context ); 1163 } 1106 1164 }
Note: See TracChangeset
for help on using the changeset viewer.