Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can enable the REST API for “advert” post type by adding the code below in your theme functions.php file

    
    add_filter( "adverts_post_type", function( $args, $type = null ) {
      if( $type != "advert" ) {
        return $args;
      }
      $args["show_in_rest"] = true;
      return $args;
    }, 10, 2 );
    

    Please note we did not test the WPAdverts with REST enabled, so if you decide to do that the run some tests on your website to make sure everything is running properly.

    Thread Starter Neha Unadkat

    (@nehaunadkat)

    Hello,

    Thanks for response.

    I have tried this but it didn’t work for me. Actually i want to display user advertise dashboard functionality in mobile app like view add,create add and all for that i need rest api for that.

    Is it possible?

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i am checking the code and it seems to work fine, i can see it enables REST API for ads since in wp-admin / Classifieds panel WPAdverts is using Gutenberg instead of the classic editor when the code is enabled.

    As for the other question if by a mobile app you mean a native Android or iOS application then i am afraid it will not work as your app will not “understand” the shortcodes.

    You should have access to the Ads themself via the REST API so you should be able to build a list of Ads and the Ad details pages, how to do that i cannot tell as i am not really familiar with mobile development.

    Plugin Author Greg Winiarski

    (@gwin)

    Also with the code added when i will go to http://example.com/wp-json/wp/v2/ i can see that the “advert” is registered in the REST API?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How to enable wp-json WordPress rest API’ is closed to new replies.