Get post/page breadcrumbs

@since 0.9
@access public
@global object Post object
@param string $post_id ID of current post
@param array $options Options, if any
@return array Post breadcrumb ancestors
343891
public function post_breadcrumbs( $post_id, $options = array() ) {

		global $post;

		// Default options
		$defaults = array(
			'shorten'			=> 30,		// shorten post titles
			'show_parents'		=> true,	// show parents posts
		);
		$options = wp_parse_args( $options, $defaults );

		// Start breadcrumbs
		$post_breadcrumbs = array();

		// Get post
		if ( $post = get_post( $post_id ) ) {

			// Current post
			$title = get_the_title();
			if ( empty( $title ) ) { // no title? use post type or post format name?
				if ( $post_format = get_post_format() ) { // show post format if have it
					$title = get_post_format_string( $post_format );
				} elseif ( $post_type_obj = get_post_type_object( get_post_type() ) ) { // otherwise show post type name
					$title = $post_type_obj->labels->singular_name;
				}
			}

				// Tidy the title
				$title = $this->tidy_title( $title, $options );

				// Add breadcrumb
				$this->add_breadcrumb( $post_breadcrumbs, array(
					$title,
					get_permalink()
				) );

			// Parent posts?
			if ( $options['show_parents'] && ! empty( $post->post_parent ) ) {

				$parent_post_breadcrumbs = array();

				// Traverse through parent posts
				$parent_post_id = $post->post_parent;
				while ( $parent_post_id ) { // keep moving down levels until there are no more parent posts

					$parent_post = get_post( $parent_post_id );
					$parent_post_id  = $parent_post->post_parent; // if this parent has a parent, while loop will continue

					$parent_post_breadcrumbs[] = array(
						$this->tidy_title( get_the_title( $parent_post->ID ), $options ),
						get_permalink( $parent_post->ID )
					);

				}

				// Reverse parent post array and merge into main breadcrumbs
				$this->add_breadcrumbs_array( $post_breadcrumbs, array_reverse( $parent_post_breadcrumbs ) );

			}

		}

		return apply_filters( 'ctc_post_breadcrumbs', $post_breadcrumbs, $post_id );

	}
674490
public static function findByID($postID, $postTypeSlug = '')
    {
        $postTypeSlug = ($postTypeSlug ? $postTypeSlug : PostType::getSlug());
        $postObj = (new Post())->setTable($postTypeSlug);
        $post = $postObj
            ->where('postID', $postID)
            ->with($postObj->getDefaultRelations(getPostType($postTypeSlug)))
            ->first();
        return $post;
    }
598047
public function getBreadcrumb(Page $page = null, $breadcrumb = array())
    {
        if (null === $this->breadcrumb) {
            $page = (null !== $page) ? $page : $this;
            $breadcrumb[] = $page;
            if (null !== $page->getParent()) {
                return $this->getBreadcrumb($page->getParent(), $breadcrumb);
            } else {
                $this->breadcrumb = $breadcrumb;
            }
        }

        return $this->breadcrumb;
    }
772372
public function updateNavCLasses($sorted_menu_items, $args)
    {
        $object_post_type = get_post_type();
        if (! get_post_type()) {
            return $sorted_menu_items;
        }

        // Get post page ID array
        $page_ids = $this->get_page_ids();
        if (! isset($page_ids[$object_post_type])) {
            return $sorted_menu_items;
        }

        foreach ($sorted_menu_items as &$item) {
            if ($item->type === 'post_type' && $item->object === 'page' && intval($item->object_id) === intval($page_ids[$object_post_type])) {
                if (is_singular($object_post_type)) {
                    $item->classes[]             = 'current-menu-ancestor';
                    $item->current_item_ancestor = true;
                }
                if (is_post_type_archive($object_post_type)) {
                    $item->classes[]    = 'current-menu-item';
                    $item->current_item = true;
                }
            }
        }

        return $sorted_menu_items;
    }
1046441
public function getBreadcrumbs($currentPid = 0, $defaultLabel = '列表', $url = '', $urlParams = [], $appendToTop = [], $append = [])
    {
        /** @var \yii\db\ActiveRecord $model */
        $model = $this->owner;
        // 顶级面包屑
        $breadcrumbs[] = $defaultLabel;
        // 非顶级数据则获取该值的所有父级数据
        if (!empty($currentPid)) {
            if ($model->{$this->pkField} == $currentPid) {
                $self = $model;
            } else {
                /** @var self $self 当前`$currentPid`的模型数据 */
                $self = $model::find()->select([
                    $this->pkField,
                    $this->showTitleField,
                    $this->parentField,
                ])->where([$this->pkField => $currentPid])->one();
            }
            
            // 当前模型数据的所有父级数据
            $parentIds = $self->getParentIds();
            if (!empty($parentIds)) {
                $parents = $model::find()->select([
                    $this->pkField,
                    $this->showTitleField,
                    $this->parentField,
                ])->where([
                    $this->pkField => $parentIds,
                ])->asArray()->all();
                $parents = ArrayHelper::listToTree($parents, $this->pkField, $this->parentField, '_child');
                // 所有的父级面包屑
                $breadcrumbs = ArrayHelper::merge($breadcrumbs, $this->_toFormatBreadcrumbs($parents));
            }
            // 包含自身面包屑
            $breadcrumbs[$self->{$this->pkField}] = $self->{$this->showTitleField};
        }
        
        // 格式化面包屑
        foreach ($breadcrumbs as $id => &$title) {
            $arr = [];
            $arr['label'] = $title;
            if ($currentPid != $id || $append) {
                $arr['url'][] = $url;
                $arr['url'][$this->breadcrumbParentParam] = $id ?: null;
                if ($urlParams) {
                    $arr['url'] = ArrayHelper::merge($urlParams, $arr['url']);
                }
            }
            $title = $arr;
        }
        
        // 添加自定义面包屑在已有面包屑后面
        if ($append) {
            $breadcrumbs = ArrayHelper::merge($breadcrumbs, $append);
        }
        
        // 添加自定义面包屑在所有面包屑前端
        if ($appendToTop) {
            $breadcrumbs = ArrayHelper::merge($appendToTop, $breadcrumbs);
        }
        
        return $breadcrumbs;
    }
652062
public function getPermalinkAfter($postId, $post)
    {
        if (wp_is_post_revision($postId)) {
            return;
        }

        remove_action('save_post', array($this, 'getPermalinkAfter'), 10, 2);

        $this->permalinkAfter = get_permalink($this->postId);

        if ($post->post_status === 'trash') {
            $this->trashed = true;
        }

        if ($this->permalinkBefore && !empty($this->permalinkBefore)) {
            $this->detectChangedPermalink();
        }
    }
177230
public function find($id, array $options = [])
    {
        $topic = Arr::get($options, 'topic');

        if ($topic == 'payment') {
            $response = $this->gateway->commit('get', $this->gateway->buildUrlFromString('collections/notifications').'/'.$id);

            if (!$response->success()) {
                return $response;
            }

            $responseData = $response->data();

            $id = Arr::get($responseData, 'merchant_order_id');
        }

        return $this->gateway->commit('get', $this->gateway->buildUrlFromString('merchant_orders').'/'.$id, [], $options);
    }
29373
public function Breadcrumbs()
    {
        $basePath = str_replace(Director::protocolAndHost(), '', Director::absoluteBaseURL());
        $relPath = parse_url(
            substr($_SERVER['REQUEST_URI'], strlen($basePath), strlen($_SERVER['REQUEST_URI'])),
            PHP_URL_PATH
        );
        $parts = explode('/', $relPath);
        $base = Director::absoluteBaseURL();
        $pathPart = "";
        $pathLinks = array();
        foreach ($parts as $part) {
            if ($part != '') {
                $pathPart .= "$part/";
                $pathLinks[] = "<a href=\"$base$pathPart\">$part</a>";
            }
        }
        return implode('&nbsp;&rarr;&nbsp;', $pathLinks);
    }
1301765
public static function delete_all_attachment( $post_ID, $force = false ) {

		if ( get_post_status( $post_ID ) === false ) {
			return false;
		}

		$counter = 0;

		$attachments = get_posts(
			[
				'post_type'      => 'attachment',
				'posts_per_page' => 100,
				'post_status'    => 'any',
				'post_mime_type' => 'image/jpeg, image/png, image/gif',
				'post_parent'    => $post_ID,
			]
		);

		foreach ( $attachments as $attachment ) {
			if ( wp_delete_attachment( $attachment->ID, $force ) !== false ) {
				$counter++;
			}
		}

		return $counter;
	}
889906
static function get($post_id)
	{
		global $db;
		//$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id
		//		FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
		//		WHERE p.post_id=" . intval($this->post_id) . " AND t.topic_id = p.topic_id";
		$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($post_id);
		$result = $db->sql_query($sql);
		$post_data = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		if(!$post_data)
		{
			//post does not exist, return false
			return false;
		}


		return post::from_array($post_data);
	}
826713
function ajax_render_location( $options = array() )
	{
		// defaults
		$defaults = array(
			'group_id' => 0,
			'rule_id' => 0,
			'value' => null,
			'param' => null,
		);
		
		$is_ajax = false;
		if( isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'acf_nonce') )
		{
			$is_ajax = true;
		}
		
		
		// Is AJAX call?
		if( $is_ajax )
		{
			$options = array_merge($defaults, $_POST);
		}
		else
		{
			$options = array_merge($defaults, $options);
		}
		
		// vars
		$choices = array();
		
		
		// some case's have the same outcome
		if($options['param'] == "page_parent")
		{
			$options['param'] = "page";
		}

		
		switch($options['param'])
		{
			case "post_type":
				
				// all post types except attachment
				$choices = apply_filters('acf/get_post_types', array(), array('attachment'));

				break;
			
			
			case "page":
				
				$post_type = 'page';
				$posts = get_posts(array(
					'posts_per_page'			=>	-1,
					'post_type'					=> $post_type,
					'orderby'					=> 'menu_order title',
					'order'						=> 'ASC',
					'post_status'				=> 'any',
					'suppress_filters'			=> false,
					'update_post_meta_cache'	=> false,
				));
				
				if( $posts )
				{
					// sort into hierachial order!
					if( is_post_type_hierarchical( $post_type ) )
					{
						$posts = get_page_children( 0, $posts );
					}
					
					foreach( $posts as $page )
					{
						$title = '';
						$ancestors = get_ancestors($page->ID, 'page');
						if($ancestors)
						{
							foreach($ancestors as $a)
							{
								$title .= '- ';
							}
						}
						
						$title .= apply_filters( 'the_title', $page->post_title, $page->ID );
						
						
						// status
						if($page->post_status != "publish")
						{
							$title .= " ($page->post_status)";
						}
						
						$choices[ $page->ID ] = $title;
						
					}
					// foreach($pages as $page)
				
				}
				
				break;
			
			
			case "page_type" :
				
				$choices = array(
					'front_page'	=>	__("Front Page",'acf'),
					'posts_page'	=>	__("Posts Page",'acf'),
					'top_level'		=>	__("Top Level Page (parent of 0)",'acf'),
					'parent'		=>	__("Parent Page (has children)",'acf'),
					'child'			=>	__("Child Page (has parent)",'acf'),
				);
								
				break;
				
			case "page_template" :
				
				$choices = array(
					'default'	=>	__("Default Template",'acf'),
				);
				
				$templates = get_page_templates();
				foreach($templates as $k => $v)
				{
					$choices[$v] = $k;
				}
				
				break;
			
			case "post" :
				
				$post_types = get_post_types();
				
				unset( $post_types['page'], $post_types['attachment'], $post_types['revision'] , $post_types['nav_menu_item'], $post_types['acf']  );
				
				if( $post_types )
				{
					foreach( $post_types as $post_type )
					{
						
						$posts = get_posts(array(
							'numberposts' => '-1',
							'post_type' => $post_type,
							'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
							'suppress_filters' => false,
						));
						
						if( $posts)
						{
							$choices[$post_type] = array();
							
							foreach($posts as $post)
							{
								$title = apply_filters( 'the_title', $post->post_title, $post->ID );
								
								// status
								if($post->post_status != "publish")
								{
									$title .= " ($post->post_status)";
								}
								
								$choices[$post_type][$post->ID] = $title;

							}
							// foreach($posts as $post)
						}
						// if( $posts )
					}
					// foreach( $post_types as $post_type )
				}
				// if( $post_types )
				
				
				break;
			
			case "post_category" :
				
				$terms = get_terms( 'category', array( 'hide_empty' => false ) );
				
				if( !empty($terms) ) {
					
					foreach( $terms as $term ) {
						
						$choices[ $term->term_id ] = $term->name;
						
					}
					
				}
				
				break;
			
			case "post_format" :
				
				$choices = get_post_format_strings();
								
				break;
			
			case "post_status" :
				
				$choices = array(
					'publish'	=> __( 'Published', 'acf'),
					'pending'	=> __( 'Pending Review', 'acf'),
					'draft'		=> __( 'Draft', 'acf'),
					'future'	=> __( 'Future', 'acf'),
					'private'	=> __( 'Private', 'acf'),
					'inherit'	=> __( 'Revision', 'acf'),
					'trash'		=> __( 'Trash', 'acf'),
				);
								
				break;
			
			case "user_type" :
				
				global $wp_roles;
				
				$choices = $wp_roles->get_names();

				if( is_multisite() )
				{
					$choices['super_admin'] = __('Super Admin', 'acf');
				}
								
				break;
			
			case "taxonomy" :
				
				$choices = array();
				$simple_value = true;
				$choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value);
								
				break;
			
			case "ef_taxonomy" :
				
				$choices = array('all' => __('All', 'acf'));
				$taxonomies = get_taxonomies( array('public' => true), 'objects' );
				
				foreach($taxonomies as $taxonomy)
				{
					$choices[ $taxonomy->name ] = $taxonomy->labels->name;
				}
				
				// unset post_format (why is this a public taxonomy?)
				if( isset($choices['post_format']) )
				{
					unset( $choices['post_format']) ;
				}
			
								
				break;
			
			case "ef_user" :
				
				global $wp_roles;
				
				$choices = array_merge( array('all' => __('All', 'acf')), $wp_roles->get_names() );
			
				break;
				
				
			case "ef_media" :
				
				$choices = array('all' => __('All', 'acf'));
			
				break;
				
		}
		
		
		// allow custom location rules
		$choices = apply_filters( 'acf/location/rule_values/' . $options['param'], $choices );
							
		
		// create field
		do_action('acf/create_field', array(
			'type'	=>	'select',
			'name' => 'location[' . $options['group_id'] . '][' . $options['rule_id'] . '][value]',
			'value'	=>	$options['value'],
			'choices' => $choices,
		));
		
		
		// ajax?
		if( $is_ajax )
		{
			die();
		}
								
	}
1259878
protected function getSidebarPostId() {
		$post_id = intval( get_the_ID() );

		if ( $this->isBlog() ) {
			$post_id = intval( get_option( 'page_for_posts' ) );
		}

		$post_id = intval( apply_filters( 'app_sidebar_context_post_id', $post_id ) );

		return $post_id;
	}
435886
private function deletePost($id, $postType)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postType, 'delete', $id, true)) {
            return $this->noPermission();
        }

        // Check if this post type has posts
        // Post type should not be able to be deleted if it has posts
        if(Post::isInMenuLinks($id, $postType)) {
            return $this->response("You can't delete this Post because It is being used in menu links", 403);
        }

        $post = (new Post())->setTable($postType);
        $post = $post->find($id);

        if(!$post) {
            // create delete task
            Task::create('post', 'delete', [$id], ['postType' => $postType]);
            return $this->response('Post doesn\'n exist in the database. If it exist in archive, it will be deleted after 10 min.', 500);
        }

        if ($post->delete()) {
            // Delete categories relations of this post
            DB::table(categoriesRelationTable($postType))->where('postID', $id)->delete();
            // Delete tags relations of this post
            DB::table(tagsRelationTable($postType))->where('postID', $id)->delete();
            return true;
        }
        return false;
    }
1306426
protected function getLinks($options = array())
	{
		global $wp_query, $wp_rewrite;

		//use the query for paging
		$current = $wp_query->query_vars['paged'] > 1 ? $wp_query->query_vars['paged'] : 1;

		//set the "paginate_links" array to do what we would like it it.
		//Check the codex for examples http://codex.wordpress.org/Function_Reference/paginate_links
		$pagination = array(
			'base'     => @add_query_arg('paged', '%#%'),
			//'format' => '',
			'showall'  => false,
			'end_size' => $this->endSize,
			'mid_size' => $this->midSize,
			'total'    => $wp_query->max_num_pages,
			'current'  => $current,
			'type'     => 'array',
			'prev_text' => $this->defaults['prev_text'],
			'next_text' => $this->defaults['next_text'],
		);

		//build the paging links
		if ($wp_rewrite->using_permalinks())
		{
			$pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
		}

		//more paging links
		if (!empty($wp_query->query_vars['s']))
		{
			$pagination['add_args'] = array('s' => urlencode(get_query_var('s')));
		}

		$aLinks = paginate_links($pagination);

		if (!$aLinks)
		{
			return null;
		}

		return $this->parseWpLinks($aLinks);

	}
137726
public static function retrieve($id, $options = null)
    {
        $url = static::classUrl().'/'.$id;
        return static::_directRequest('get', $url, null, $options);
    }
723216
function get_posts( $post_ids )
	{
		// validate
		if( empty($post_ids) )
		{
			return $post_ids;
		}
		
		
		// vars
		$r = array();
		
		
		// find posts (DISTINCT POSTS)
		$posts = get_posts(array(
			'numberposts'	=>	-1,
			'post__in'		=>	$post_ids,
			'post_type'		=>	apply_filters('acf/get_post_types', array()),
			'post_status'	=>	'any',
		));

		
		$ordered_posts = array();
		foreach( $posts as $p )
		{
			// create array to hold value data
			$ordered_posts[ $p->ID ] = $p;
		}
		
		
		// override value array with attachments
		foreach( $post_ids as $k => $v)
		{
			// check that post exists (my have been trashed)
			if( isset($ordered_posts[ $v ]) )
			{
				$r[] = $ordered_posts[ $v ];
			}
		}
		
		
		// return
		return $r;
	}
343870
function mf_get_post_values( $post_id ) {
    global $wpdb;

    $raw = $wpdb->get_results(
      "SELECT
        mfpm.meta_id,
        mfpm.field_name,
        mfpm.field_count,
        mfpm.group_count,
        pm.meta_value
      FROM
        ".MF_TABLE_POST_META." as mfpm
      LEFT JOIN
       ".$wpdb->postmeta." as pm
      ON
        ( mfpm.meta_id = pm.meta_id )
      WHERE
        mfpm.post_id = ".$post_id
    );

    $data = array();

    foreach( $raw as $key => $field ){
      $data[$field->field_name][$field->group_count][$field->field_count] = $field->meta_value;
    }

    return $data;
  }