admin管理员组文章数量:1130349
I'm trying to be able to fetch all the posts of a particular post type on my website. The post type should be called 'opportunities'. I'm new to wordpress so a bit out of my depth. The posts in question actually have their on button on the admin sidebar so they could be something entirely different from a 'custom_post_type'. Any help I could get on this would be much appreciated.
*edit: These are the notes I got from a developer I'm trying to help:
"To access the database with opportunities from the UK office we need them to make these available through an API. This can be done by their developer by changing a few lines in their code. It’s explained at: / after making the changes I need to know the URL where I can retrieve the opportunities through JSON."
I'm not a developer, I'm more or less just the guy that got asked to help with website in our office.
I'm trying to be able to fetch all the posts of a particular post type on my website. The post type should be called 'opportunities'. I'm new to wordpress so a bit out of my depth. The posts in question actually have their on button on the admin sidebar so they could be something entirely different from a 'custom_post_type'. Any help I could get on this would be much appreciated.
*edit: These are the notes I got from a developer I'm trying to help:
"To access the database with opportunities from the UK office we need them to make these available through an API. This can be done by their developer by changing a few lines in their code. It’s explained at: https://developer.wordpress/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/ after making the changes I need to know the URL where I can retrieve the opportunities through JSON."
I'm not a developer, I'm more or less just the guy that got asked to help with website in our office.
Share Improve this question edited Oct 29, 2018 at 13:56 Luke asked Oct 26, 2018 at 13:43 LukeLuke 11 bronze badge 10 | Show 5 more comments1 Answer
Reset to default 0I think what you mean is do an onclick event.
So, you can do this with JavaScript. Create your link as per usual <a id=“myCustomLink” href=“#” onclick=“MyFunction();return false;”>huh! I’m a link!</a>
And now some script
<script>
function MyFunction() {
//Make it do whatever here! For example:
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Rerun false; will prevent the browser directing to the link... unless you want it to? If so then just remove this and add a link in-place of the # after the href.
However! A much cleaner way of doing this would be to do it as JQuery and attach the ID as an onclick handler. Like so:
$(‘#myLink’).click(function(){ MyFunction(); return false; });
Hope this helps!
I'm trying to be able to fetch all the posts of a particular post type on my website. The post type should be called 'opportunities'. I'm new to wordpress so a bit out of my depth. The posts in question actually have their on button on the admin sidebar so they could be something entirely different from a 'custom_post_type'. Any help I could get on this would be much appreciated.
*edit: These are the notes I got from a developer I'm trying to help:
"To access the database with opportunities from the UK office we need them to make these available through an API. This can be done by their developer by changing a few lines in their code. It’s explained at: / after making the changes I need to know the URL where I can retrieve the opportunities through JSON."
I'm not a developer, I'm more or less just the guy that got asked to help with website in our office.
I'm trying to be able to fetch all the posts of a particular post type on my website. The post type should be called 'opportunities'. I'm new to wordpress so a bit out of my depth. The posts in question actually have their on button on the admin sidebar so they could be something entirely different from a 'custom_post_type'. Any help I could get on this would be much appreciated.
*edit: These are the notes I got from a developer I'm trying to help:
"To access the database with opportunities from the UK office we need them to make these available through an API. This can be done by their developer by changing a few lines in their code. It’s explained at: https://developer.wordpress/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/ after making the changes I need to know the URL where I can retrieve the opportunities through JSON."
I'm not a developer, I'm more or less just the guy that got asked to help with website in our office.
Share Improve this question edited Oct 29, 2018 at 13:56 Luke asked Oct 26, 2018 at 13:43 LukeLuke 11 bronze badge 10- Your question is not clear. Can you please elaborate more. So, We'll help you. – maheshwaghmare Commented Oct 26, 2018 at 13:47
- These are the notes I got from a developer I'm trying to help: "To access the database with opportunities from the UK office we need them to make these available through an API. This can be done by their developer by changing a few lines in their code. It’s explained at: developer.wordpress/rest-api/extending-the-rest-api/… after making the changes I need to know the URL where I can retrieve the opportunities through JSON." – Luke Commented Oct 26, 2018 at 13:59
-
Do you have set the
'show_in_rest' => trueand'rest_controller_class' => 'WP_REST_Posts_Controller'parameters while registering your post typeopportunities? If yes the you can access them with rest api endpoint like: example/wp-json/wp/v2/opportunities – maheshwaghmare Commented Oct 26, 2018 at 14:06 -
Like default post rest api endpoint - yoursite/wp-json/wp/v2/posts. Change
http://yoursitewith your domain and try yourself. It'll works! If not then share your website URL for reference. – maheshwaghmare Commented Oct 26, 2018 at 14:07 - Thanks for your quick answers. Where would I find that in the code to make sure it's set to true? I have put it in the theme functions but not sure if that was right place. – Luke Commented Oct 26, 2018 at 14:17
1 Answer
Reset to default 0I think what you mean is do an onclick event.
So, you can do this with JavaScript. Create your link as per usual <a id=“myCustomLink” href=“#” onclick=“MyFunction();return false;”>huh! I’m a link!</a>
And now some script
<script>
function MyFunction() {
//Make it do whatever here! For example:
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Rerun false; will prevent the browser directing to the link... unless you want it to? If so then just remove this and add a link in-place of the # after the href.
However! A much cleaner way of doing this would be to do it as JQuery and attach the ID as an onclick handler. Like so:
$(‘#myLink’).click(function(){ MyFunction(); return false; });
Hope this helps!
本文标签: jsonHow do I use URL to fetch all posts of a particular custom post type
版权声明:本文标题:json - How do I use URL to fetch all posts of a particular custom post type? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749224044a2335410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


'show_in_rest' => trueand'rest_controller_class' => 'WP_REST_Posts_Controller'parameters while registering your post typeopportunities? If yes the you can access them with rest api endpoint like: example/wp-json/wp/v2/opportunities – maheshwaghmare Commented Oct 26, 2018 at 14:06http://yoursitewith your domain and try yourself. It'll works! If not then share your website URL for reference. – maheshwaghmare Commented Oct 26, 2018 at 14:07