Skip to content

Instantly share code, notes, and snippets.

View monecchi's full-sized avatar

Adriano Monecchi monecchi

View GitHub Profile
function custom_taxonomies_terms_links() {
global $post, $post_id;
// get post by post id
$post = &get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type);
$out = "<ul>";
foreach ($taxonomies as $taxonomy) {
@monecchi
monecchi / wp-related-by-category
Created June 14, 2016 19:39 — forked from troutacular/wp-related-by-category
WordPress Related by Category
@monecchi
monecchi / wp-query-ref.php
Created June 9, 2016 23:13 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@monecchi
monecchi / functions.php
Created June 8, 2016 12:58 — forked from billerickson/functions.php
Use the built-in post counter
<?php
/**
* Use the built-in post counter
*
* Sometimes you'll want to keep track of which post you're on in a loop.
* Some people create their own $loop_counter (ex: Genesis, https://gist.github.com/4675237 ).
* There's a better way! A loop counter is built into $wp_query. Ex:
*
* global $wp_query;
* echo $wp_query->current_post
@monecchi
monecchi / aq-portfolio-block.php
Last active June 8, 2016 12:08 — forked from contempoinc/aq-portfolio-block.php
Portfolio Page Aqua Builder Block
<?php
/** A simple text block **/
if(!class_exists('AQ_Portfolio_Block')) {
class AQ_Portfolio_Block extends AQ_Block {
//set and create block
function __construct() {
$block_options = array(
'name' => 'Portfolio',
@monecchi
monecchi / wp-json-api-v2-custom-post-types.php
Last active June 7, 2016 17:42
Get Custom Post Types Using the WP API V2
<?php
/*
* Easy! Using the example of a custom post type called ‘the_event’,
* you’d just put the following into your functions.php file (or plugin).
* Credits go to author: https://bay-a.co.uk/wordpress-tips/wp-api-v2-tips/
*/
add_action( 'init', 'add_events_to_json_api', 30 );
function add_events_to_json_api(){
@monecchi
monecchi / array-easily-exit-foreach-loop-after-x-number-of-iterations.php
Last active June 7, 2016 03:22
Array easily exit the foreach loop after x number of iterations
// Credit goes to authors of answers here: http://stackoverflow.com/a/2865393/1152876
<?php
/*
* Example array, the values are grabbed from a custom field on WordPress.
* Works well if you need a solution that can accept any array.
*/
$array = get_post_meta( get_the_ID(), '_prefix_my_custom_field', true );
@monecchi
monecchi / array-filter-iteration-limit-count.php
Last active June 7, 2016 02:54
Receive one array as input, filter values from it, and output as a new array.
// Receive one array as input, filter values from it, and output as another array.
// The function should loop through up to x iterations.
// Credits go to the author of the answer here: http://stackoverflow.com/a/7274450/1152876
*/
* Exit the foreach loop when count is reached.
* Use a foreach to iterate over the full array, and if the stated maximum count isn't reached, process the whole array.
* Otherwise, if the maximum iteration is reached, jump out of the loop.
*/
@monecchi
monecchi / wp_rss_feed.php
Created June 4, 2016 21:22 — forked from nickeforsberg/wp_rss_feed.php
Multiple Custom Post Types to Wordpress main RSS Feed.
// Add custom post types main RSS feed.
function wp_rss_feed( $query ) {
if ( $query->is_feed() )
$query->set( 'post_type', array( 'post', 'events', 'books' ) );
return $query;
}
add_filter( 'pre_get_posts', 'wp_rss_feed' );
@monecchi
monecchi / gist:d4cd69e3806a4c1a2183293c8334576b
Created June 4, 2016 21:19 — forked from brunoalves/gist:7683005
Custom post type feed rewrite
<?php
function artigo_feed_rewrite( $wp_rewrite ) {
$feed_rules = array(
'feed/artigos' => 'index.php?post_type=listing&feed=rss2'
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
// regerar regras de permalinks depois de ativar / implementar esse código