Updating Wordpress Permalinks - wordpress

I have created a plugin that uses custom posts. To get these to display the permalinks need re-saving, no need to change anything, they just need re-saving.
There must be a way to do this using a hook but I can't work out how to do this. The function flush_rules looks like it might do the job but it doesn't seem to work.
Sample code here: http://codex.wordpress.org/Rewrite_API/flush_rules

Ok solved it.
You just have to add the flush to the custom post registration:
register_post_type('custompostname',$args);
flush_rewrite_rules(false);
So simple really, just took me a while to find it.

Related

How to create Child Plugin for wordpress

Actually I have changed some code in WordPress Store Locator. I want it to remain when plugin will update. So I want to create a child plugin for that. Any ideas on how I could manage it?
This varies plugin to plugin, and it sometimes isn't even possible, other times plugins have documentation to extend them easily (such as WooCommerce and Gravity Forms). Some of them create Action Hooks with do_action() that let you extend the functionality easily. A common example is updating a post after a Gravity Form is submitted with their gform_after_submission hook.
Effectively, it depends on what you want to do, and how the plugin implements the functionality you want to change. If they add text with a Closure or Anonymous Function, it will be harder to modify said text, and you may have to look at something strange like doing a run-time find and replace using Output Buffering, typically on the template_redirect hook.
If you want to remove something a plugin does, you can often unhook it with remove_action. This can be a bit tricky depending on how the plugin is instantiated, sometimes its as simple as:
remove_action( 'some_hook', 'function_to_remove' );
Other times it's more complicated like:
global $plugin_class_var;
remove_action( 'some_hook', array($plugin_class_var, 'function_to_remove') );
Those are the basics of extending (or even 'shrinking'?) a plugin's functionality, and it's not always doable appropriately. Unfortunately the narrow answer to your question is outside of the scope of what we can provide from StackOverflow.
From here, you'll need to figure out exactly what you want to do with the plugin, and dig through the plugin's files to see if there's an appropriate hook or function you can use. If you're still stuck, you'll need to post a new question (don't update this one) with your exact desired result and anything you've tried, and the relevant code that goes along with it. "I want to change a plugin without editing core files" isn't nearly specific enough. "I want to replace an icon with a custom icon in this plugin, here's what I've tried" is specific enough to possibly answer.
Good luck!
I just went through myself and I had so many changes that I couldn't just override the actions.
I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.
I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.
https://github.com/ThomasDepole/wordpress-child-plugin-tool
As per WordPress standard, it's called plugin's addon.
if the plugin has provided any action to update that functionality then you can use it with your addon (child plugin).
Here I am sending a link for reference.
https://developer.wordpress.org/reference/functions/add_action/

Custom Post Type links not working

I'm wanting to make an employee page populated from a custom post type called "Employees". It lists http://www.domain.com/employees/joe/ as the permalink but the the actual page shows up as unavailable. Am I missing something on the taxonomy side?
Thanks in advance!
Answering it because I just figured it out, but after quite a bit of googling, nothing came up, so hopefully this helps somebody.
Reset the permalinks!
For some reason, if you create a custom post type after you initially set your permalink structure, it needs to be reset. Go to your settings/permalinks, set them to default, save, and then set them back how you want, save, and you're good to go.
The permalink structure needs resetting because this regenerates the rewrite rules within wordpress, allowing the different URL segment structures to be properly recognised and processed.
Wordpress rewriting works very well, but getting around it for custom post types, custom taxonomies etc. has added an extra set of needs to the system, which are slowly being improved. The custom rewrite system was added, and it's continued development is gradually making it easier to tackle issues like this.
In many cases, a custom taxonomy is the easiest way to go.

Advanced Custom Fields not saving at all now

I downloaded and installed Advanced Custom Fields 4.1.6 the other day and I used it a few times for some time and it worked perfectly, but for some reason now none of my custom fields seem to be saving and I'm not getting any errors or anything. I don't think that I have done anything at all that could have possibly broken this.
Has this happened to anyone else? And what could possibly be the issue?
I think you might have to take a look at export function the plugin provides. Select a field group you created and hit export. It'll generate some code which is pretty good commented with tips and advice. There might be some information there for good use for 'ya.
Example by the plugin developer:
Include in theme
The Advanced Custom Fields plugin can be included within a theme. To do so, move the ACF plugin inside your theme and add the following code to your functions.php file:
include_once('advanced-custom-fields/acf.php');
To remove all visual interfaces from the ACF plugin, you can use a constant to enable lite mode. Add the following code to your functions.php file before the include_once code:
define( 'ACF_LITE', true );
Hope it helps.
/Paul
Since my rep isn't high enough to reply to #Kortschot's response, I'll comment here.
I got this error while testing a new theme. It appears the theme has ACF bundled into the theme, which triggers the "Cannot redeclare acf_filter_post_id()" error. For obvious reasons (you can't run two instances of the plugin in the same install). #Kortschot's reference to including ACF in a theme helped solve my problem.
Now I have to figure out how to access ACF if I want to customize fields on pages/posts...
I'm gonna go ahead and reply to this old question in hopes that it helps someone out. I have been having this problem where my fields would not update on my custom posts. I usually have multiple tabs open to make navigation easier in the backend of WP. It turns out that when I closed all other tabs except the current one I'm editing, the fields update every time!
I have same problem with Advanced custom fields plugin , i resolve my issue by adding one line code in advanced-custom-fields/core/controllers/post.php
add_action('pre_post_update', array($this, 'save_post'));
after
add_action('save_post',array($this, 'save_post'), 10, 1);
line number 33, 34.
I had the same problem and fixed it by creating unique field names.

Return wordpress user to original page after they register

I'm working on a Wordpress site which has various features that are only available to registered users. I need to prompt the users to register/login at various places, and after they do I want to return them to the original page they were on.
I know how to do this manually, but my suspicion is that there is a way to take advantage of built-in Wordpress functions, so I'd rather not "reinvent the wheel." I've searched for solutions but I've only found strategies that involve a hard-coded, static return page after registration. I DON'T want to do this. I'm looking for a way to keep track of the referring page, and return to it after registration. Thanks in advance.
EDIT1: I've located what I thought I was looking for, which is the filter hook login_redirect. It appears to be designed for exactly what I want to do, but I don't seem to be able to get it to work.
The implementation should be pretty straight-forward, so I'm not sure what I could be doing wrong. Here's the code in my theme's functions.php:
function redirect_to_function($redirect_to, $request, $user)
{
return 'http://www.mywebsite.com/redirect_page/';
}
add_filter( 'login_redirect', 'redirect_to_function', 10, 3 );
EDIT2:
I think I solved the mystery as to why the redirect_to filter isn't working, as well as the solution using the hidden field named "redirect_to" (see comments below). I'm using the s2Member plugin to manage membership levels, and I suspect that it is overriding the built-in wordpress functionality.
I think there is not such plugins which match your requirement 100%. Bit i suggest to customize this plugin. http://wordpress.org/extend/plugins/peters-login-redirect/
My problem was related to a specific plugin I was using that was over-riding my hooks. See my edits above.

Order wordpress post by custom field value?

Currently i have tried half internet codes ( :D ) to make this work, but with no luck.
I'm not a wordpress guru so it's quite bit hard. Basically what i want is to make plugin that will alter all post ordering across all wordpress blog based on date value in custom field.
For example i add custom field to each post (meta_key=bb_history) and (meta_value=2011-04-03).
So where i would hook or what filter should i use to get this working somehow? I guess you can use posts_where, posts_join, posts_orderby actions to make something?
You don't want a plug-in. Just edit your query_posts statement in the template in question.
query_posts($query_string . '&meta_key=YOURFIELDNAME');

Resources