WP Job Manager - Job Types - Custom Permalink - wordpress

This question is WP Job Manager for Wordpress specific.
I activated the plugins native "Job Types" taxonomy and created 2 job types, "Schools" and "Hotels".
I would like to customise the permalink, so it reads the actual name of the job-type.
Bt default the Listing Base URL for all WP Job Manager listings is : /listings/
What I would like to achieve is that from the default:
example.com/listings/my-job-listing-1
and
example.com/listings/my-job-listing-2
it would read:
example.com/schools/my-job-listing-1
and
example.com/hotels/my-job-listing-2
Would something like this be possible?

Try this: https://mikejolley.com/2013/12/04/use-wordpress-url-manipulation-functions/
Remove the current link arguments with remove_query_arg(); and add the new ones. With add_query_arg();

Related

User access to CPT (Custom Post Type) without access to regular posts

I have created a custom post type that for the sake of this question we can call "my_cpt".
I have also created a new role which we can call "my_role".
What I want to do is give "my_role" access to "my_cpt" without adding the "edit_posts" capability because that gives access to other post types which I do not want the role to have access to.
I have tried variations of numerous bits of code I have found but none have worked so I don't really know where to begin. Based on that I don't have any base code to display here.
A plugin like this one should enable you to do this: https://www.role-editor.com/
Ended up being easier than I thought.
I created a couple capabilities... "read_my_cpt" and "edit_my_cpt".
The "my_role" has permissions to both the capabilities.
I then just had to change the capability_type for the CPT to "my_cpt" instead of "post"

CategoryManyToManyField tuns to emty QuerySet in non edit mode

I write a new plugin for aldryn_newsblog application. I want to list articles by categories. The plugin takes the list of categories using CategoryManyToManyField.
The plugin displays the articles having requested categories only in edit mode. As soon as I publish page with newly added plugin it displays none of the articles. I checked that self.categories.all() becomes empty.
Why it is happening?
This is for;
aldryn-newsblog2.1.1
Django==1.11.17
django-cms==3.5.3
It acts the same on local django development server and on remote apache
class NewsBlogCategoryPlugin(PluginEditModeMixin, AdjustableCacheModelMixin, NewsBlogCMSPlugin):
....
categories = CategoryManyToManyField('aldryn_categories.Category', verbose_name=_('categories'), blank=True)
....
def get_articles(self, request):
print (self.categories.all())
queryset = Article.objects
main_qs = queryset.all().filter(categories =
self.categories.all())
return main_qs
I believe that the issue is this:
when your page is published, the plugin instance is copied
in the published version of the page, there is now a new plugin instance
this new plugin instance does not have the relations to the Categories that the original did
You need to ensure that when a plugin is copied, so are its relations.
See handling relations in the django CMS documentation.
Thank you #Daniele. I just have added following the handling-relations
def copy_relations(self, oldinstance):
self.categories = oldinstance.categories.all()
And now it works

WP Rest API: Can't seem to get embedded data from the post object

I am working with the WORDPRESS REST API and Wordpress version 4.8 for an internal network page at a local office. We have permalinks disabled (security reasons) and thus I am accessing the posts object like so:
https://url/blogs/usernamehere/?rest_route=/wp/v2/posts/12345
I am able to do a GET request and can get the posts data into my view template with no issues. However, I can't seem to figure out how to consume additional content in the post object . I have followed the documentation and tried to do:
https://url/blogs/usernamehere/?rest_route=/wp/v2/posts/12345?_embed=true
But, I get a STATUS 404 .
How would I correctly apply the embed function in the URL so I can get the additional data associated with the post?
Pass the _embed global parameter without a value, per the documentation.
you should do this:
https://url/blogs/usernamehere/?_embed=true&rest_route=/wp/v2/posts/12345
Basically you add _embed=true at before other parameters and after & add other parameters.

what does ep mask in the wordpress's register taxonomy function exactly do?

I'm registering a custom taxonomy for my blog using the register_taxonomy function which has an argument rewrite
for rewrite the URLs using some parameters
, one of them is ep_mask . Wordpress claims that it should be used when you want to add an endpoint for the Taxonomy URL. I just don't understand why to add an endpoint and what it's benefit. Please if an example with a result is available it will be better.
Thanks in advance
The endpoint mask value is used to tell WordPress what kind of endpoint additions a certain registered item supports, and to which a developer can add
endpoints to via add_rewrite_endpoint().
By default taxonomies (as far as I know) offer no ep_mask (defaults to EP_NONE), but for custom taxonomies you could use a custom EP mask, or one of the built-in ones (e.g. EP_PAGES) to make the permalink structure work similarly to something else.
Assuming you set the ep_mask value to EP_PERMALINK | EP_PAGES, you could then register a new endpoint using
add_rewrite_endpoint('json', EP_PERMALINK | EP_PAGES);
Which in turn would allow you to suffix your taxonomy URLs with json and the value json would be available as a query variable in $wp_query. Then you can use the value as a check to alter the query, templates, and other related things when the page loads.
You can read more about endpoints here: https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/ (A bit old, but should still reflect how the core works with endpoints.)
The benefit is that you can use the endpoint with pretty permalinks.
If you do not specify the EP_MASK, pretty permalinks will not work
The description of ep_mask in the documentation of register_taxonomy() contains a link to an article that explains it in detail.
A quote from that article:
If we wanted to add our endpoint to all post permalinks we would use EP_PERMALINK. For both posts and pages: EP_PERMALINK | EP_PAGES. For posts, pages, and categories: EP_PERMALINK | EP_PAGES | EP_CATEGORIES.
There are specific examples in that article:
https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/

Is it possible to create categories that are available in a Wordpress theme by default?

Is there a way of having categories available right after installing a theme.
For instance, if a theme post content to a loop which retrieves posts with the category "Tagline". Is there a way of having the category "Tagline" by default (in the theme)?
(So the end user wouldn't have to create it himself/herself)
Try using wp_insert_category(); -- see: http://codex.wordpress.org/Function_Reference/wp_insert_category
You'd probably have to write an init function in functions.php that runs the first time the theme is activated and calls the above function. You'll want to write some error handling that prevents it from being run multiple times, however.

Resources