Skip to content

Instantly share code, notes, and snippets.

<?php
/*********************************************
Contests CPT
**********************************************/
/* Contest CPT :: Initiate CPT
**********************************************/
function vs_register_contests_post_type() {
@salcode
salcode / wp-title-like-where.php
Created March 31, 2016 15:50
WordPress mu-plugin to add support for "title_like" in WP_Query to add a LIKE WHERE clause to a query.
<?php
/**
* Example usage to find all Titles with a comma:
* $example_query = new WP_Query(
* array(
* 'title_like' => ','
* )
* );
*/
@salcode
salcode / only-display-post-info-on-posts.php
Created March 31, 2016 19:33
WordPress mu-plugin for Genesis to only display post info when the post type is "post". This applies to the single template, archive, and search results page.
<?php
/**
* Genesis: Only display post info when post type is "post"
*/
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
add_action( 'genesis_entry_header', 'fe_genesis_post_info', 12 );
function fe_genesis_post_info() {
if ( 'post' === get_post_type() ) {
genesis_post_info();
@salcode
salcode / why-not-preprocess-comment-for-empty-comment.md
Created June 9, 2016 10:32
Why you can't use the `preprocess_comment` filter on an empty comment.
@salcode
salcode / populate-blank-comment.js
Created June 9, 2016 14:12
jQuery JavaScript to populate a blank comment with an Automated Comment. This is being done on the client side because on the server side there is no filter available before the check for an empty comment body.
jQuery('#commentform').on('submit', function() {
var $comment = jQuery('#comment');
if ( '' === $comment.val().trim() ) {
$comment
.css({'color':'#fff'})
.val( 'Automated Comment: ' + Math.floor( new Date().getTime() / 1000 ) );
}
});
@salcode
salcode / home.php
Created June 14, 2016 10:15
Genesis home.php template to display content before posts on blog page.
<?php
/**
* File for home.php
*
* Blog page template with page description before blog posts.
*
* @package example;
*/
add_action( 'genesis_before_loop', 'fe_home_genesis_before_loop' );
@salcode
salcode / minimal-cpt-definition.php
Last active January 21, 2020 15:41
Minimal WordPress code to register the Custom Post Type `fe_recipe`
<?php
/**
* Register CPT `fe_recipe`
*/
add_action( 'init', 'fe_recipe_cpt' );
/**
* Register CPT `fe_recipe`
*/
<?php
/**
* The code to register a WordPress Custom Post Type (CPT) `fe_recipe`
* with a custom Taxonomy `fe_recipe_tag`
* @package fe_recipe
*/
add_action( 'init', 'fe_recipe_cpt' );
/**
<?php
/**
* Set the number of posts on the Custom Post Type archive for `fe_recipe` to 5.
*/
add_action( 'pre_get_posts', 'fe_modify_number_of_posts_per_page' );
/**
* Modify Posts Per Page for CPT `fe_recipe`
*
@salcode
salcode / fe-prevent-slug-conflict.php
Created July 19, 2016 04:15
WordPress code to reserve some top level Permalink slugs.
<?php
/**
* Prevent top level permalink slugs that will cause conflicts.
*
* New rewrite slugs are introduced when CPTs or Custom Taxonomies are created.
* This code adds a check when Pages or Posts are created, that their Permalink
* does not conflict with one of the reserved top level slugs you define.
*
* In the case of a bad (i.e conflicting slug), WordPress appends a "-2" to
* the permalink.