We provide the code snippets and content on this page without any guarantee or support. In most cases, these pages are created on requests or based on individual solutions sent to us by other users. After it was published, we are only reviewing the code and content when we are made aware of an issue. Please let us know if you find one.

Please only use the codes if you understand them and know how to add custom code to your WordPress site.

By default, Advanced Ads doesn’t enable the REST API for ads.

Use the following code to change the post type definition and enable the REST API endpoint for ads.

/** * Enable REST API support for the ad post type */ add_filter( 'advanced-ads-post-type-params', function( $post_type_params ) { $post_type_params[ 'show_in_rest' ] = true; return $post_type_params; } );
Code language: PHP (php)

This also requires unchecking the option Advanced Ads > Settings > General > Disable ads > Disable ads in the REST API and setting the Unlimited ad injection in the Content section to 1.

Now, you can find the REST endpoint returning the ads under /wp-json/wp/v2/advanced_ads.

  • The default amount of entries you see on the REST endpoint is limited to 10. You can navigate to more results using the page parameter or extend the list to include more results with per_page. For more details see paginations in the REST API manual.
  • You need to enable permalinks in WordPress for the REST API to work.
  • You can find more information in the WordPress REST API handbook.

Use the following code to change the taxonomy definition and enable the REST API endpoint for groups.

/** * Enable REST API support for the ad group taxonomy */ add_filter( 'advanced-ads-group-taxonomy-params', function( $taxonomy_params ) { $taxonomy_params[ 'show_in_rest' ] = true; return $taxonomy_params; } );
Code language: PHP (php)

Now, you can find the REST endpoint returning the groups under /wp-json/wp/v2/advanced_ads_groups.

Please see Adding REST API Support for Custom Post Types for further adjustment options.