Skip to content

Instantly share code, notes, and snippets.

@arelthia
arelthia / functions.php
Created August 6, 2015 17:06
Change the number of post that are displayed per page for specific CPTs
add_action( 'pre_get_posts', 'tht_change_cpt_posts_per_page' );
/**
* Change Posts Per Page for CPT Archive
*/
function tht_change_cpt_posts_per_page( $query ) {
if( $query->is_main_query() && !is_admin() && (is_post_type_archive( 'definitions' )|| is_post_type_archive( 'question' )) ) {
$query->set( 'posts_per_page', '18' );
}
}
@arelthia
arelthia / functions.php
Last active August 29, 2015 14:26
Force CPT to use a specific template
/**
* Force Template
*/
add_filter( 'template_include', 'tht_force_template' );
function tht_force_template($template){
if ( 'cpt_name' == get_post_type()){
$template = get_query_template( 'template-name' );
}
return $template;
@arelthia
arelthia / functions.php
Created August 6, 2015 17:44
Change the label for Pods Groups. Create seperate groups(meta boxes).
function tht_add_pods_groups () {
pods_group_add( 'book', 'About The Book', 'book_featured, book_short_title, book_subtitle, book_cover_image, book_cover_caption, book_description, book_background_image, book_author, book_available_at' );
pods_group_add( 'place', 'Available From', 'place_name, place_link, place_icon, related_book' );
}
add_action( 'pods_meta_groups', 'tht_add_pods_groups' );
@arelthia
arelthia / archive-book.php
Created August 6, 2015 17:48
Genesis Custom Pods Archive template
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'tht_book_archive_custom_loop' );
/**
* Genesis custom loop
*/
function tht_book_archive_custom_loop() {
$books = new Pod('book');
$params = array(
'order' => 'ASC',
'orderby' => 'title',
@arelthia
arelthia / front-page.php
Last active November 23, 2019 20:57
Pods find (query) based on field value - Used on Genesis home page
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'tht_featured_home', 5 );
function tht_featured_home() {
$where = "book_featured.meta_value='1'";
$params = array(
'where'=> $where,
'order' => 'ASC',
'limit' => 1,
@arelthia
arelthia / variable.php
Created December 2, 2015 01:50
WooCommerce Change Attribute None Option
<?php
/**
* Variable product add to cart
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.4.0
* In theme/child theme directory add woocommerce/single-product/add-to-cart/
*/
if ( ! defined( 'ABSPATH' ) ) {
@arelthia
arelthia / gfs3.php
Created December 28, 2016 19:43 — forked from renventura/gfs3.txt
Send Gravity Forms file uploads to Amazon S3
<?php
/**
* Send Gravity Forms file uploads to Amazon S3
* @author Ren Ventura <EnageWP.com>
* @link http://www.engagewp.com/send-gravity-forms-file-uploads-to-amazon-s3/
*/
//* Include the required library
include_once 'inc/S3.php';
@arelthia
arelthia / get-post-type.js
Created December 31, 2016 05:06
Get WordPress CPT from front end
(function( $ ) {
'use strict';
var attrs, attr, postType;
postType = null;
$(function() {
// Look to see what type of post type we're working with
attrs = $( 'body' ).attr( 'class' ).split( ' ' );
@arelthia
arelthia / Add class to menu
Last active June 9, 2017 18:34
Add custom classes to WordPress menus
// Add extra classes for the first and last items in all WordPress menus
add_filter( 'wp_nav_menu_objects', function ( $items ) {
if ( ! empty( $items ) ) {
$items[1]->classes[] = 'menu-item-first';
$items[ count( $items ) ]->classes[] = 'menu-item-last';
}
return $items;
} );
@arelthia
arelthia / functions.php
Last active June 23, 2017 15:49
Force ssl on one page and force http on specific pages.
add_action( 'template_redirect', 'pintop_ssl_redirect', 1 );
function pintop_ssl_redirect() {
//page that should be ssl
if ( is_page( 1264 ) && ! is_ssl() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']), 301 );
exit();
} else {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );