My site includes a third party plugin which includes the below:
register_post_type( 'portfolio',
...
'rewrite' => array( 'slug' => 'portfolio' )
...
)
However for my site I need it to effectively say
...
'rewrite' => array( 'with_front' => false, 'slug' => 'portfolio' )
...
However I don't want to edit this third party plugin and cause problems for future updating. Is it possible to define the extra argument in my own plugin or theme (I don't think a theme can change rewrite)?
For the benefit of anyone else, the solution I've arrived at after another frustrating day working on this was to create a new plugin which read in all the existing plugin details via
get_post_types(array('name' => 'portfolio'),'objects');
edit the rewrite
$rebuiltportfolio["rewrite"]=array('with_front' => false, 'slug' => 'portfolio');
and then re-registered the post type
register_post_type( 'portfolio', $rebuiltportfolio);
You do need to ensure that this action has a higher priority than the original one.
Related
I want to add '/blog' in front of my all blog posts. I changed this from 'Setting -> Permalinks -> Custom Structure' but it adds '/blog' to all custom posts as well. I am using lots of custom posts and custom categories.
I found some solutions here. In this solution all working fine but there is no solution to remove '/blog' from custom category url.
I got the solution. Just add 'rewrite' => array( 'with_front' => false ), this into custom category arguments array.
IMPORTANT: Do not forget to flush and regenerate the rewrite rules database after modifying rules. From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.
See below Eg.
$args = array(
'labels' => $labels,
'rewrite' => array( 'with_front' => false ),
'hierarchical' => true,
);
register_taxonomy( $taxonomy, $object_type, $args );
http://127.0.0.1/wordpress/{{movie}}/watch-appetite-for-love-2016-free-on-123movieshub/
I want all my url to show movie word before postname
By setting this custom permalink value /movie/%postname%/ as Custom Structure at /wp-admin/options-permalink.php page.
It sounds like you would benefit from using a custom post type. These take on the URL of their name by default if you have pretty urls. You can also force the slug you want. This is a basic post type there are a lot more options on the Wordpress Developer Codex.
function create_movie_post_type() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'movie'),
)
);
}
add_action( 'init', 'create_movie_post_type' );
This gives you a lot more control over that particular post type and keeps it separate from the native "post".
When setting 'hierarchical' => true to a custom post type and assigning a parent to a page with this custom post type throws 404. It is posible to make this work?
Expected result: http://example.com/parent-page/page-title/
This works with Wordpress normal pages, but not with custom post types (404 not found).
Thanks in advance!
Since I just noticed you wanted a permalink structure exactly like pages, you can modify the rewrite parameter when you register your post type. Here is an example on how to make it just like pages structure:
$args = array(
'labels' => $labels,
'hierarchical' => true, // just to get parent child relationships with your custom post [but you already knew this part]
'description' => 'Your custom post type description here',
'has_archive' => false,
'rewrite' => array('slug' => '/'), // we rewrite the slug to the root url so that it has no post type prefix
'with_front' => false, // This is optional but just in case your posts are set to /blog/post-name this will make it /post-name for your custom post type
'capability_type' => 'post',
'supports' => array(
'title', 'editor', 'author', 'thumbnail', 'page-attributes'
)
);
register_post_type( 'post_type', $args );
Also make sure you update the permalink structure after you make these changes so Wordpress can rewrite the rules.
I'm using the Rules module in Drupal 7, and I tried to add a new Rules "Action"
I followed the steps described in How to create an custom rule action using hook_rules_action_info? to create a custom rule action using hook_rules_action_info:
I tried to create a sample file (save_nid.rules.inc) in the folder /rules/module/.
And I also tried to create a module folder in /site/all/module/save_nid/.
My code in save_nid.rules.inc looks like so:
function rules_save_nid_action_info() {
return array(
'save_nid_action' => array(
'label' => t('Custom Action'),
'parameter' => array(
'param1' => array(
'type' => 'int',
'label' => t('Parameter Label'),
),
'param2' => array(
'type' => 'commerce_order',
'label' => t('Parameter Label2'),
),
),
'configurable' => FALSE,
'group' => t('ABC Custom module action'),
'callbacks' => array(
'execute' => 'abc_custom_action',
),
),
}
After I cleared the Drupal cache, I didn't see my "custom rule" in the list.
What am I missing or doing wrong?
In your case, the machine name of your custom module seems to be save_nid.
So if you want to use hook_rules_action_info in your module, your function needs to be named save_nid_rules_action_info, instead of rules_save_nid_action_info.
Not sure if it is the "only" problem why you can't get it to work, but at least it is "a" problem you need to address.
PS: make sure to save that custom coding in your custom module's folder (in /site/all/module/save_nid/).
I am quit new to wordpress and have a problem I cannot seems to solve even with a day of google searching. This is what I did:
I have created a custom post type called lookbook. This works fine and I can add new items and such.
I added a taxonomy so I could add an category to it.
function lookbook_taxonomy() {
register_taxonomy( 'jeans','lookbook',
array(
'hierarchical' => true,
'label' => 'jeans',
'query_var' => true,
'rewrite' => true
)
);
}
Using wp_query or query_posts I can retrieve the lookbook items and display their content.
(problem) When I pres the category link provided by word press the page just goes back to index. The link changes to the desired filter however NO post are being filtered. I tried all kinds of stuff but I can seems to find a way to just press the category link and just diplay those post.
update: (code I used to register post type)
add_action('init', 'lookbook_register_post_type');
function lookbook_register_post_type() {
register_post_type('lookbook', array(
'labels' => array(
'name' => __('lookbook'),
'singular_name' => __('lookbook')),
'public' => true,
'capability_type' => 'post',
'supports' => array(
'title',
'excerpt'
),
'has_archive' => true,
'taxonomies' => array('category','post_tag')
)
);
}
You'll need to add 'has_archive' => true to your register_post_type arguments array if it's not already there.
Additionally, make sure you have the necessary template files ready. Read up on Wordpress' Template Hierarchy.
If you show us the code you used to register the post type, as well as what code makes up "the category link", we might be of more help!