Isotope, WP REST API, and AJAX...Oh my!

16
Isotope, WP REST API, and AJAX oh my! An example in the wild...

Transcript of Isotope, WP REST API, and AJAX...Oh my!

Page 1: Isotope,  WP REST API, and AJAX...Oh my!

Isotope WP REST APIand AJAXoh myAn example in the wild

About meNameAustin Gil

Work Visceral (httpsthisisvisceralcom)ldquoWe craft brands and experiences for the worldrsquos leading causesrdquo

Position Lead Developer

WP Experience 3 years

Recent Project Using Rest API

Healthy Newborn Network - httpwwwhealthynewbornnetworkorg

Process1 get_posts() shows initial posts and sets up array of IDs for posts to load

2 Create gallery markup using Isotope for animations and filters

3 When a filter is clicked WP REST API sets up post objects based on IDs

4 AJAX takes the data from the REST API and loads it

The toolbox Not necessary to know but helpful for understanding

Isotope - httpisotopemetafizzyco

WP REST API - httpv2wp-apiorg

jQuery AJAX - httpapijquerycomjqueryajax

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 2: Isotope,  WP REST API, and AJAX...Oh my!

About meNameAustin Gil

Work Visceral (httpsthisisvisceralcom)ldquoWe craft brands and experiences for the worldrsquos leading causesrdquo

Position Lead Developer

WP Experience 3 years

Recent Project Using Rest API

Healthy Newborn Network - httpwwwhealthynewbornnetworkorg

Process1 get_posts() shows initial posts and sets up array of IDs for posts to load

2 Create gallery markup using Isotope for animations and filters

3 When a filter is clicked WP REST API sets up post objects based on IDs

4 AJAX takes the data from the REST API and loads it

The toolbox Not necessary to know but helpful for understanding

Isotope - httpisotopemetafizzyco

WP REST API - httpv2wp-apiorg

jQuery AJAX - httpapijquerycomjqueryajax

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 3: Isotope,  WP REST API, and AJAX...Oh my!

Recent Project Using Rest API

Healthy Newborn Network - httpwwwhealthynewbornnetworkorg

Process1 get_posts() shows initial posts and sets up array of IDs for posts to load

2 Create gallery markup using Isotope for animations and filters

3 When a filter is clicked WP REST API sets up post objects based on IDs

4 AJAX takes the data from the REST API and loads it

The toolbox Not necessary to know but helpful for understanding

Isotope - httpisotopemetafizzyco

WP REST API - httpv2wp-apiorg

jQuery AJAX - httpapijquerycomjqueryajax

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 4: Isotope,  WP REST API, and AJAX...Oh my!

Process1 get_posts() shows initial posts and sets up array of IDs for posts to load

2 Create gallery markup using Isotope for animations and filters

3 When a filter is clicked WP REST API sets up post objects based on IDs

4 AJAX takes the data from the REST API and loads it

The toolbox Not necessary to know but helpful for understanding

Isotope - httpisotopemetafizzyco

WP REST API - httpv2wp-apiorg

jQuery AJAX - httpapijquerycomjqueryajax

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 5: Isotope,  WP REST API, and AJAX...Oh my!

The toolbox Not necessary to know but helpful for understanding

Isotope - httpisotopemetafizzyco

WP REST API - httpv2wp-apiorg

jQuery AJAX - httpapijquerycomjqueryajax

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 6: Isotope,  WP REST API, and AJAX...Oh my!

get_posts()

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 7: Isotope,  WP REST API, and AJAX...Oh my!

Isotope markup

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 8: Isotope,  WP REST API, and AJAX...Oh my!

WP REST APIDefault location

wp-jsonwpv2posts

httpsdev-hnnthisisvisceralcomwp-jsonwpv2posts

Add WP Query filters such as posts_per_page

filter[posts_per_page]=1

httpsdev-hnnthisisvisceralcomwp-jsonwpv2postsfilter[posts_per_page]=1

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 9: Isotope,  WP REST API, and AJAX...Oh my!

AJAX

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 10: Isotope,  WP REST API, and AJAX...Oh my!

Gotchas

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 11: Isotope,  WP REST API, and AJAX...Oh my!

Doesnrsquot support certain fieldsFeatured image

Author details

Advanced Custom Fields

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 12: Isotope,  WP REST API, and AJAX...Oh my!

Custom post types

Not supported by default Going to wp-jsonwpv2custom-post-type did not work Must be enabled when registering post types

Apply filters with ldquorest_prepare_(your post type)rdquo

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 13: Isotope,  WP REST API, and AJAX...Oh my!

Why not wp_ajax()

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 14: Isotope,  WP REST API, and AJAX...Oh my!

So why all the fusshellip

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 15: Isotope,  WP REST API, and AJAX...Oh my!

REST API makes it possible to build a separate application and access data in a WP site

That means we can build with any language PHP Ruby Python Node Angular React

even static HTMLhttplocalhostrestwpindexhtml

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools
Page 16: Isotope,  WP REST API, and AJAX...Oh my!

Useful Toolsconsolelog(allTheThings)

JSON browser extension - Chrome JSONView httpschromegooglecomwebstoredetailjsonviewchklaanhfefbnpoihckbnefhakgolnmchl=en

  • Isotope WP REST API and AJAX oh my
  • Slide 2
  • Recent Project Using Rest API
  • Process
  • The toolbox Not necessary to know but helpful for understand
  • get_posts()
  • Isotope markup
  • WP REST API
  • AJAX
  • Gotchas
  • Doesnrsquot support certain fields
  • Custom post types
  • Why not wp_ajax()
  • So why all the fusshellip
  • Slide 15
  • Useful Tools