Permalink
Browse files

Fixes to Query class methods

  • Loading branch information...
Nomafin committed Oct 19, 2018
1 parent 5c0bb87 commit cb1f7ec52767b26e09e799f87a425c589dd3c620
Showing with 15 additions and 3 deletions.
  1. +1 −0 CHANGELOG.md
  2. +14 −3 classes/query.php
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Make the menuhelper show the correct current item even on category or tag archives.
- Query::get_post() and Query::get_acf_post() methods to function properly without global post object existence.
## [1.16.8] - 2018-10-15
@@ -48,10 +48,15 @@ public static function get_post( $id = null, $args = array() ) {
extract( $options );
// If id is not the same as global post get_post by id.
if ( $post->ID !== $id ) {
// Throw error if we have no post to fetch
if ( empty( $post ) && empty( $id ) ) {
throw new \Exception( 'DustPress\Query::get_post() requires either global post object existence or defined $id parameter.' );
}
// Get the post from $id parameter if it's different from the global post object or the global object does not exist.
else if ( empty( $post ) || $post->ID !== $id ) {
$current_post = get_post( $id );
}
// Use global post
else {
$current_post = $post;
}
@@ -104,9 +109,15 @@ public static function get_acf_post( $id = null, $args = array() ) {
extract( $options );
if ( $post->ID !== $id ) {
// Throw error if we have no post to fetch
if ( empty( $post ) && empty( $id ) ) {
throw new \Exception( 'DustPress\Query::get_acf_post() requires either global post object existence or defined $id parameter.' );
}
// Get the post from $id parameter if it's different from the global post object or the global object does not exist.
else if ( empty( $post ) || $post->ID !== $id ) {
$acfpost = get_post( $id );
}
// Use global post
else {
$acfpost = $post;
}

0 comments on commit cb1f7ec

Please sign in to comment.