Skip to content

Instantly share code, notes, and snippets.

@alwerner
alwerner / Display Wordpress categories for Custom Post Types
Last active December 14, 2015 05:59
Display categories for Custom Post Types, add to functions.php
// Display categories for Custom Post Types, add to functions.php
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','news'); //substitute cpt - in this case 'news' - for post type
@alwerner
alwerner / Display Wordpress Custom Post Types on home page
Last active December 14, 2015 05:59
Display Wordpress Custom Post Types on home page, add to functions.php
// Display Custom Post Types on home page, add to functions.php
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'news' ) ); //add cpt, in this case 'news' to array
return $query;
@alwerner
alwerner / Using Wordpress Tags with Custom Post Types
Last active December 14, 2015 05:59
Using Wordpress Tags with Custom Post Types, goes in functions.php
// Using Tags with Custom Post Types, goes in functions.php
function add_custom_types( $query ) {
if( is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// this gets all post types:
// $post_types = get_post_types();
// alternately, you can add just specific post types using this line instead of the above:
$post_types = array( 'post', 'news' );
@alwerner
alwerner / Adding a git alias to .gitconfig
Last active December 13, 2015 19:38
Adding a git alias to .gitconfig
git config --global alias.<NAME> "<COMMAND>"
@alwerner
alwerner / Wordpress Custom Post Type Pagination
Last active December 1, 2015 22:40
for "news" custom post type
<?php
// Define custom query parameters
$custom_query_args = array(
'post_type' => 'news',
'orderby' => 'asc',
'paged' => $paged,
'posts_per_page' => 2
);
git rm -r --cached .
This removes everything from the index, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
@alwerner
alwerner / php conditional loading based on host
Last active October 12, 2015 20:29
php conditional loading based on host
<?php
if ($_SERVER["HTTP_HOST"] == 'mydomain.com' || $_SERVER["HTTP_HOST"] == 'www.mydomain.com' ) {
// insert, for instance, analytics code here.
}
@alwerner
alwerner / Git Remove Deleted Files
Last active October 10, 2015 10:27
Remove Deleted Files
# to remove already deleted files:
git add -u .
git commit -m "manually deleting files"
@alwerner
alwerner / ssh path to github repo
Last active October 9, 2015 08:08
ssh path to github repo
Make sure you're using the SSH one:
ssh://git@github.com/username/repo.git.
And NOT the https or git one.
Fix the url in the .git/config file.