{"id":18249680,"date":"2025-01-17T12:27:25","date_gmt":"2025-01-17T12:27:25","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/post_type-php-error\/"},"modified":"2025-01-17T12:29:40","modified_gmt":"2025-01-17T12:29:40","slug":"post_type-php-error","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/post_type-php-error\/","title":{"rendered":"post_type php error"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">in \\plugins\\blockmeister\\includes\\Pattern_Builder\\Admin\\BlockMeister_Pattern_List_Table.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">there is post_type php error on line 948.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The issue occurs in the line <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$wp_query-&gt;query&#091;'post_type']<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">which triggers an error if the post_type key does not exist. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After modifying the code as follows, the error message no longer appears.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function filter_table_list_rows_on_category( $posts, $wp_query ) {<br \/>    if ( !isset( $wp_query-&gt;query&#091;'post_type'] ) || $wp_query-&gt;query&#091;'post_type'] !== 'blockmeister_pattern' <br \/>        || !isset( $_GET&#091;'filter_action'] ) || !isset( $_GET&#091;'category'] ) || $_GET&#091;'category'] === '0' ) {<br \/>        return $posts;<br \/>    }<br \/>    <br \/>    $category_filter = $_GET&#091;'category'];<br \/>    $filtered_posts = &#091;];<br \/>    <br \/>    foreach ( $posts as $post ) {<br \/>        $pattern_name = $this-&gt;get_pattern_name( $post );<br \/>        $registered_block_pattern = $this-&gt;get_registered_pattern( $pattern_name );<br \/>        $pattern_categories = ( isset( $registered_block_pattern&#091;'categories'] ) ? $registered_block_pattern&#091;'categories'] : &#091;] );<br \/>        if ( in_array( $category_filter, $pattern_categories, true ) ) {<br \/>            $filtered_posts&#091;] = $post;<br \/>        }<br \/>    }<br \/>    <br \/>    return $filtered_posts;<br \/>}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-18249680","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18249680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18249680\/revisions"}],"predecessor-version":[{"id":18249685,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18249680\/revisions\/18249685"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18249680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}