A shared tag with AI prompts and code snippets
From workspace: CodeWP
Team: Main
Total snippets: 3
3 snippets
This PHP script for WordPress sorts a list of awards custom post types. It first retrieves the awards from the database including their year, category, and type. Then, it sorts them using a custom sorting function based on a predefined order set in the WordPress ACF options page for both categories and types, and by year.
<?php global $wpdb; // Get all awards $query = " SELECT p.ID, p.post_title, MAX(CASE WHEN pm.meta_key = 'awd_year' then pm.meta_value ELSE NULL END) as awd_year, MAX(CASE WHEN pm.meta_key = 'awd_sort_cat' then pm.meta_value ELSE NULL...
This file contains a WordPress function that changes the HTTP status code from 404 to 410 for pages that are not found. It's designed to inform search engines that the content is permanently removed, potentially improving SEO by preventing indexing of non-existent pages.
<?php /** * Sets the HTTP status code to 410 for 404 Not Found pages. * * This function checks if the current request resulted in a 404 error and, if so, * sets the HTTP status code to 410 (Gone). It should be attached to the...
This file contains a set of functions that implement an automatic logout feature for 'customer' role users in WordPress after a period of inactivity. It uses JavaScript to track user activity and a WordPress AJAX action to handle the logout process securely.
<?php function cwpai_logout_script() { if (is_user_logged_in() && current_user_can('customer')) { $logout_time = 30; // Set the logout time in seconds $logout_nonce = wp_create_nonce('cwpai_logout_nonce'); $logout_url =...