Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added search/filter results for blog posts #890

Merged
merged 19 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
90 changes: 50 additions & 40 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions web/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
define( 'WP_DEBUG_LOG', __DIR__ . '/wp-content/debug.log' ); // Moves log file to writable location.
define( 'SCRIPT_DEBUG', true );
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); // stops admin email sent.
define( 'LOAD_MEDIA_FROM_PRODUCTION_URL', 'https://www.cncf.io' ); // Sets url for loading media files on dev instance.

// fixes small problem with LH-HSTS
if ( ! isset( $_SERVER['HTTP_HOST'] ) ) {
Expand Down Expand Up @@ -217,7 +216,6 @@
define( 'WP_DEBUG_LOG', __DIR__ . '/wp-content/debug.log' ); // Moves log file to writable location.
define( 'SCRIPT_DEBUG', true );
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); // stops admin email sent.
define( 'LOAD_MEDIA_FROM_PRODUCTION_URL', 'https://www.cncf.io' ); // Sets url for loading media files on dev instance.

define( 'WP_PLUGIN_DIR', dirname( __FILE__ ) . '/wp-content/plugins' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,17 @@ class="wp-block-spacer case-study-overview__logo"></div>
<!-- Project area -->
<?php if ( ! empty( $projects ) && ! is_wp_error( $projects ) ) { ?>
<div class="case-study-overview__projects">

<p
class="is-style-spaced-uppercase"><?php echo esc_html( $projects_used ); ?></p>

<p class="is-style-spaced-uppercase"><?php echo esc_html( $projects_used ); ?></p>
<div class="case-study-overview__project-icons">
<?php
foreach ( $projects as $project ) {
?>
<div class="case-study-overview__project-icon">
<a title="View <?php echo esc_html( $project->name ); ?>" href="/projects/<?php echo esc_html( $project->slug ); ?>">
<img loading="lazy"
src="<?php echo esc_url( get_template_directory_uri() ) . '/images/projects/' . esc_html( $project->slug ) . '-icon-color.svg'; ?>"
alt="<?php echo esc_html( $project->name ); ?>">
</a>
</div>
<?php
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public function display_plugin_setup_page() {
*/
public function validate( $input ) {

$this->tag_blog_posts_with_projects();

$options = get_option( $this->plugin_name );

$options['show_hello_bar'] = ( isset( $input['show_hello_bar'] ) && ! empty( $input['show_hello_bar'] ) ) ? 1 : 0;
Expand Down Expand Up @@ -251,6 +253,50 @@ public function validate( $input ) {
return $options;
}

/**
* Get all projects found more than once in the content.
*
* @param string $content The content of the post.
* @param array $projects The projects to search for.
*/
private function get_project_tags( $content, $projects ) {
$project_tags = array();
foreach ( $projects as $project ) {
if ( substr_count( $content, $project->name ) > 1 ) {
$project_tags[] = $project->name;
}
}
return $project_tags;
}

/**
* Tag blog posts with projects.
* This is a temporary function used once to tag all blog posts by projects that appear in its copy.
*/
private function tag_blog_posts_with_projects() {
$myposts = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
'category' => 230,
)
);
$projects = get_terms( 'lf-project' );

foreach ( $myposts as $post ) {
if ( get_the_terms( $post->ID, 'lf-project' ) ) {
continue;
}

// only add projects if there are none already assigned.
$project_tags = $this->get_project_tags( $post->post_content, $projects );
if ( ! empty( $projects ) ) {
wp_set_post_terms( $post->ID, $project_tags, 'lf-project' );
}
}
wp_reset_postdata();
}

/**
* Update options
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
// delete any KTP posts which aren't in $synced_ids.
$query = new WP_Query(
array(
'post_type' => 'lf_ktp',
'post__not_in' => $synced_ids,
'posts_per_page' => -1,
'post_type' => 'lf_ktp',
'post__not_in' => $synced_ids,
'posts_per_page' => -1,
)
);
while ( $query->have_posts() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ function geocode_location( $id ) {
}

$args = array(
'post_type' => 'lf_person',
'title' => $p->name,
'post_status' => 'publish',
'numberposts' => 1,
'post_type' => 'lf_person',
'title' => $p->name,
'post_status' => 'publish',
'numberposts' => 1,
);

if ( $image_url ) {
Expand Down Expand Up @@ -203,9 +203,9 @@ function geocode_location( $id ) {
// delete any People posts which aren't in $synced_ids.
$query = new WP_Query(
array(
'post_type' => 'lf_person',
'post__not_in' => $synced_ids,
'posts_per_page' => -1,
'post_type' => 'lf_person',
'post__not_in' => $synced_ids,
'posts_per_page' => -1,
)
);
while ( $query->have_posts() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
'show_in_nav_menus' => false,
'show_admin_column' => true,
);
register_taxonomy( 'lf-project', array( 'lf_course', 'lf_webinar', 'lf_case_study', 'lf_case_study_cn', 'lf_person', 'lf_human' ), $args );
register_taxonomy( 'lf-project', array( 'lf_course', 'lf_webinar', 'lf_case_study', 'lf_case_study_cn', 'lf_person', 'lf_human', 'post' ), $args );

$labels = array(
'name' => __( 'Author Category', 'lf-mu' ),
Expand Down Expand Up @@ -355,7 +355,7 @@
'show_in_nav_menus' => false,
'show_admin_column' => true,
);
register_taxonomy( 'lf-industry', array( 'lf_case_study' ), $args );
register_taxonomy( 'lf-industry', array( 'lf_case_study', 'post' ), $args );

$labels = array(
'name' => __( 'Industries', 'lf-mu' ),
Expand Down
Loading