/** * Update post associated with group by searching post content for them * * @since 1.0.0 * * @param \WP_Post $post */ public static function update_groups_in_post($post) { if (is_a($post, 'WP_Post')) { $obj = new \ingot\testing\object\posts($post); $current = self::find_ids($post->post_content); if (empty($current)) { $obj->add([], true); } else { $existing = $obj->get_groups(); if (empty($existing) || !empty(array_diff($existing, $current))) { $obj->add($current, true); } } } }
/** * Test that we can find query by associated post/group * * @since 1.1.0 * * @group group * @group objects * @group posts_object * * @covers ingot\testing\utility\posts::posts_by_group() */ public function testQueryByGroup() { $this->factory->post->create(['post_title' => rand(), 'post_content' => 'x']); for ($i = 5; $i <= 10; $i++) { for ($x = 0; $x <= 2; $x++) { $title = 'gr_' . $i; $id = get_post($this->factory->post->create(['post_title' => $title, 'post_content' => '!'])); $obj = new \ingot\testing\object\posts(get_post($id)); $obj->add($i); } $query = \ingot\testing\utility\posts::posts_by_group([$i]); $this->assertTrue(is_a($query, 'WP_Query')); $this->assertTrue($query->have_posts(), var_export($i)); $this->assertSame(3, $query->post_count); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame($title, $query->post->post_title); } } if (7 == $i) { $obj->add(88); $query = \ingot\testing\utility\posts::posts_by_group([7, 88]); $this->assertTrue(is_a($query, 'WP_Query')); $this->assertTrue($query->have_posts(), var_export($i)); $this->assertSame(3, $query->post_count); } } $query = \ingot\testing\utility\posts::posts_by_group([5, 6, 7, 8, 9]); $this->assertTrue($query->have_posts()); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame('!', $query->post->post_content); } } $query = \ingot\testing\utility\posts::posts_by_group([5, 6, 9]); $this->assertTrue($query->have_posts()); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame('!', $query->post->post_content); } } }