diff --git a/src/Admin/Admin.php b/src/Admin/Admin.php
index ff7485c..12d3d40 100644
--- a/src/Admin/Admin.php
+++ b/src/Admin/Admin.php
@@ -405,6 +405,8 @@ public function handle_save_source(): void {
$categories = $this->infer_categories_from_feed_url( $url );
}
+ $post_type = sanitize_key( wp_unslash( $_POST['post_type'] ?? '' ) );
+
$settings = [
'interval_minutes' => $interval,
'categories' => $categories,
@@ -413,11 +415,14 @@ public function handle_save_source(): void {
'include_keywords' => $include,
'exclude_keywords' => $exclude,
'article_length' => $length,
+ 'post_type' => $post_type,
];
if ( sanitize_key( wp_unslash( $_POST['source_type'] ?? 'rss' ) ) === 'scrape' ) {
$settings = array_merge( $settings, $this->scrape_settings_from_post() );
- \AggregateIt\Source\ScraperPostTypes::remember( (string) $settings['post_type'] );
+ }
+ if ( $post_type !== '' ) {
+ \AggregateIt\Source\ScraperPostTypes::remember( $post_type );
}
$repo = $this->plugin->sources();
@@ -490,7 +495,6 @@ private function scrape_settings_from_post(): array {
return [
'source_type' => 'scrape',
- 'post_type' => sanitize_key( wp_unslash( $_POST['post_type'] ?? '' ) ),
'processing' => in_array( $processing, [ 'passthrough', 'rewrite' ], true ) ? $processing : 'passthrough',
'scrape' => [
'discovery' => [
diff --git a/src/Admin/views/sources.php b/src/Admin/views/sources.php
index 469514b..ec07904 100644
--- a/src/Admin/views/sources.php
+++ b/src/Admin/views/sources.php
@@ -145,7 +145,7 @@
value="url ?? '' ); ?>" placeholder="https://example.com/feed">
-
|
$value ) {
- update_post_meta( $id, sanitize_key( (string) $key ), $value );
+ Meta::write( (int) $id, sanitize_key( (string) $key ), $value );
}
}
diff --git a/src/Publish/Meta.php b/src/Publish/Meta.php
new file mode 100644
index 0000000..3ab99d5
--- /dev/null
+++ b/src/Publish/Meta.php
@@ -0,0 +1,21 @@
+slugs->generate( $slug !== '' ? $slug : $keyword, $title );
- $source = $item->source_id ? $this->sources->get( $item->source_id ) : null;
- $status = $source ? $source->publish_status( $this->settings->publish_status() ) : $this->settings->publish_status();
+ $source = $item->source_id ? $this->sources->get( $item->source_id ) : null;
+ $status = $source ? $source->publish_status( $this->settings->publish_status() ) : $this->settings->publish_status();
+ $post_type = $source && $source->post_type_connection() !== '' ? $source->post_type_connection() : $this->settings->target_post_type();
$post_id = wp_insert_post(
[
- 'post_type' => $this->settings->target_post_type(),
+ 'post_type' => $post_type,
'post_status' => $status,
'post_title' => $title,
'post_name' => $slug,
@@ -53,7 +54,7 @@ public function create( int $cluster_id, Item $item, array $structured, string $
update_post_meta( $post_id, '_ai_schema_type', $item->flags['schema_type'] ?? 'Article' );
update_post_meta( $post_id, '_ai_prompt_version', AGGREGATE_IT_VERSION );
- $this->assign_terms( (int) $post_id, $item->source_id, (string) ( $structured['category'] ?? '' ) );
+ $this->assign_terms( (int) $post_id, $post_type, $item->source_id, (string) ( $structured['category'] ?? '' ) );
return (int) $post_id;
}
@@ -62,9 +63,9 @@ public function create( int $cluster_id, Item $item, array $structured, string $
* Categorize by the AI's per-article topic (created on first use), falling back to the
* feed's configured categories when the AI gives nothing. Tags come from the feed.
*/
- private function assign_terms( int $post_id, int $source_id, string $ai_category ): void {
+ private function assign_terms( int $post_id, string $post_type, int $source_id, string $ai_category ): void {
$source = $source_id ? $this->sources->get( $source_id ) : null;
- $taxes = get_object_taxonomies( $this->settings->target_post_type() );
+ $taxes = get_object_taxonomies( $post_type );
if ( in_array( 'category', $taxes, true ) ) {
$ids = [];
@@ -129,7 +130,7 @@ public function create_mapped( Item $item ): int {
update_post_meta( $post_id, '_ai_prompt_version', AGGREGATE_IT_VERSION );
foreach ( $mapped['meta'] as $key => $value ) {
- update_post_meta( $post_id, sanitize_key( (string) $key ), $value );
+ Meta::write( $post_id, sanitize_key( (string) $key ), $value );
}
foreach ( $mapped['terms'] as $taxonomy => $names ) {
if ( taxonomy_exists( (string) $taxonomy ) ) {
@@ -140,7 +141,7 @@ public function create_mapped( Item $item ): int {
$rules = $source ? $source->rules() : [];
if ( $rules ) {
foreach ( Rules::apply( $values, $rules, time() ) as $key => $value ) {
- update_post_meta( $post_id, sanitize_key( (string) $key ), $value );
+ Meta::write( $post_id, sanitize_key( (string) $key ), $value );
}
update_post_meta( $post_id, '_ai_rule_values', wp_json_encode( $values ) );
update_post_meta( $post_id, '_ai_source_id', (int) $item->source_id );
|