@since 5.2.0

@param $post_id
@param string $type_of (optional) webbook, exports

@return int
424375
static function getChapterNumber( $post_id, $type_of = 'webbook' ) {

		if ( empty( static::$__order ) ) {
			self::$__order = static::getBookStructure()['__order'];
		}
		$lookup = static::$__order;

		if ( $type_of === 'webbook' ) {
			$post_statii = [ 'web-only', 'publish' ];
		} else {
			$post_statii = [ 'private', 'publish' ];
		}

		// Sometimes the chapter number is zero, these are the reasons:
		if (
			empty( get_option( 'pressbooks_theme_options_global', [] )['chapter_numbers'] ) ||
			empty( $lookup[ $post_id ] ) ||
			$lookup[ $post_id ]['post_type'] !== 'chapter' ||
			! in_array( $lookup[ $post_id ]['post_status'], $post_statii, true )
		) {
			return 0;
		}

		// Calculate chapter number
		$i = 0;
		$type = 'standard';
		$found = array_merge( [ 'ID' => $post_id ], $lookup[ $post_id ] ); // @codingStandardsIgnoreLine
		foreach ( $lookup as $post_id => $val ) {
			if (
				$val['post_type'] !== 'chapter' ||
				! in_array( $val['post_status'], $post_statii, true )
			) {
				continue; // Skip
			}
			$type = \Pressbooks\Taxonomy::init()->getChapterType( $post_id );
			if ( 'numberless' !== $type ) {
				++$i; // Increase real chapter number
			}
			if ( $post_id === $found['ID'] ) {
				break;
			}
		}

		return ( $type === 'numberless' ) ? 0 : $i;
	}
1332399
public function options(string $id_option = null, string $type = 'page'): ?array
  {
    if (
      ($id_option = $this->_get_id_option($id_option, $type)) &&
      ($os = $this->opt->options(\func_get_args()))
    ){
      $res = [];
      foreach ( $os as $o ){
        if ( $this->pref->has($o['id']) ){
          $res[] = $o;
        }
      }
      return $res;
    }
    return null;
  }
1108071
public static function get_permalink_structure( $post_type ) {
		if ( is_string( $post_type ) ) {
			$post_type = get_post_type_object( $post_type );
		}

		if ( ! empty( $post_type->cptp ) && ! empty( $post_type->cptp['permalink_structure'] ) ) {
			$structure = $post_type->cptp->permalink_structure;
		} else if ( ! empty( $post_type->cptp_permalink_structure ) ) {
			$structure = $post_type->cptp_permalink_structure;
		} else {
			$structure = get_option( $post_type->name . '_structure', '%postname%' );
		}
		$structure = '/' . ltrim( $structure, '/' );

		return apply_filters( 'CPTP_' . $post_type->name . '_structure', $structure );
	}
1316402
public static function getRequestedTodayByIp(string $ip, int $type_id)
    {
        $query = self::find()
            ->where([
                'ip' => $ip,
                'is_validated' => 0,
                'is_deleted' => 0,
            ])
            ->andWhere(['between', 'created_at', time() - DateHelper::TIME_DAY_ONE, time()])
            ->andWhere(['type_id' => $type_id]);

        return $query->count();
    }
692724
public function get_meta( $_null, $post_ID = null, $meta_key = null, $single = false ) {

		if ( 'code' === $meta_key ) {
			$post = get_post( $post_ID );

			if ( is_object( $post ) && $this->object_type == $post->post_type ) {
				return $post->post_content;
			}
		}

		return $_null;
	}
441801
public function getAllByPostType($lang = "", $postTypeID)
    {
        $orderBy = (isset($_GET['order'])) ? $orderBy = $_GET['order'] : 'tagID';
        $orderType = (isset($_GET['type'])) ? $orderType = $_GET['type'] : 'DESC';
        // get data
        return Tag::where('postTypeID', $postTypeID)->orderBy($orderBy, $orderType)->paginate(Tag::$rowsPerPage);
    }
760976
public function edit($_type = null, $id = null)
    {
        // setting up an event for the edit
        $_event = new Event('Controller.PostTypes.beforeEdit.' . $this->_type, $this, [
            'id' => $id,
        ]);
        $this->eventManager()->dispatch($_event);

        $type = $this->Model->get($id, [
            'contain' => $this->Settings['contain']
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $type = $this->Model->patchEntity($type, $this->request->data);
            if ($this->Model->save($type)) {
                $this->Flash->success(__('The {0} has been saved.', [$this->Settings['type']]));
                return $this->redirect(['action' => 'index', 'type' => $this->_type]);
            } else {
                $this->Flash->error(__('The {0} could not be saved. Please, try again.', [$this->Settings['type']]));
            }
        }
        $this->set(compact('type'));

        // setting up an event for the edit
        $_event = new Event('Controller.PostTypes.afterEdit.' . $this->_type, $this, [
            'id' => $id,
        ]);
        $this->eventManager()->dispatch($_event);

        if (!$this->Settings['views']['edit']) {
            $this->render(Configure::read('PostTypes.AdminPostTypeViews.edit'));
            return;
        }

        $this->render($this->Settings['views']['edit']);
    }
1255121
public function post_type_link( $post_link, $post ) {

		if ( empty( $post ) || $this->object_type != $post->post_type ) {
			return $post_link;
		}

		$post_link = get_site_url() . '/';

		if ( false === strpos( $post->post_title, '*' ) ) {
			$post_link .= trim( $post->post_title, '/ ' ) . '/';
		}

		return $post_link;
	}
1062040
public function get_post_id( $check_query = false ) {
		global $post, $wp_query;
		if ( ! isset( $post ) ) {
			if ( $check_query && isset( $wp_query, $wp_query->query_vars['p'] ) ) {
				$post_id = $wp_query->query_vars['p'];
			} else {
				$post_id = 0;
			}
		} else {
			$post_id = $post->ID;
		}

		return $post_id;
	}
69154
public static function get_unique_custom_fields_by_post_type($post_type = "post") {
    global $wpdb;

    $query = "SELECT DISTINCT(type) FROM ".MF_TABLE_CUSTOM_FIELDS. " WHERE post_type = '".$post_type."'";

    $fields = $wpdb->get_col($query);
    return $fields;
  }
1290998
public function getPost($post_id)
    {
        $this->checkId($post_id);

        return $this->adapter->get(sprintf('/post/%d', $post_id));
    }
1241174
protected function set_post_type_archive( $post_type_object ) {
		$label = $post_type_object->label;
		$this->set( $label, $this->get_post_type_archive_link( $post_type_object->name ) );
	}
666711
protected function checkInternalShortcodes( $post_id, $html ) {
		// Glossary
		if ( has_shortcode( $html, \Pressbooks\Shortcodes\Glossary\Glossary::SHORTCODE ) ) {
			$this->postsWithGlossaryShortcodesToFix[] = $post_id;
		}
		// Attachments
		if ( has_shortcode( $html, \Pressbooks\Shortcodes\Attributions\Attachments::SHORTCODE ) ) {
			$this->postsWithAttachmentsShortcodesToFix[] = $post_id;
		}
		// TODO
		//  H5P not supported in WXR imports
	}
745268
private function loopBody(int $post_id, int $count): string
    {
        $post = $this->post($post_id);

        return

        $this->openPostTag($post, $count).
        $this->thumb('side', $post, $count).
        $this->openHeader($post, $count).
        $this->postInfo('title', 'before', $post, $count).
        $this->title($post, $count).
        $this->postInfo('title', 'after', $post, $count).
        $this->closeHeader($post, $count).
        $this->thumb('top', $post, $count).
        $this->content($post, $count).
        $this->excerpt($post, $count).
        $this->openFooter($post, $count).
        $this->postInfo('excerpt', 'after', $post, $count).
        $this->closeFooter($post, $count).
        $this->closePostTag($post, $count);
    }
1233682
public static function get_post_id_by_name( $post_name ) {
		global $wpdb;
		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
		$result = $wpdb->get_row($query);
		if ( !$result ) {
			return null;
		}
		return $result->ID;
	}
1201730
public static function getCodeByIp(string $ip, int $type_id)
    {
        return self::find()->where(['ip' => $ip, 'type_id' => $type_id])->orderBy(['id' => SORT_DESC])->one();
    }
64232
public static function isChildPost($postOrPostId = null)
    {
        $post = self::getPost($postOrPostId);
        if (empty($post)) {
            return false;
        }

        return $post->post_parent > 0;
    }