i have a custom field for source-links. The URL inserted in this custom field should get pinged once the post gets published. I know there is a dedicated trackback field but i want the URL from the custom field automatically added.
As far as i understand, $add_ping is exactly that.
http://codex.wordpress.org/Function_Reference/add_ping
My problem is: i don't know where to add it. I imagine if i'd write this into my theme where i display the source-link, the source gets pinged everytime the post gets visited.
So whats the proper way to add an url to get pinged on publish?
To be clear: it is not a service that i want to get pinged. More like if you'd insert a link to post B into post A's content. Once post A gets published, post B (or its blog) gets pinged. I want to insert the link into a custom field of post A, instead of its content area.
I think Felipe is right. You could try something like this:
function doCustomPing ($post_id) {
$uri_to_ping = get_post_meta($post_id, 'FIELDNAME', true);
add_ping($post_id, $uri_to_ping);
}
add_action ('publish_post', 'doCustomPing');
So every time a post if published (that includes if its edited) then a hook into publish_post will run the doCustomPing function. If you're putting this as part of a theme drop the above code in your functions.php file. Put the name if your custom field where it says FIELDNAME.
Related
I'm trying to create a glossary for my WordPress site, using a custom post type 'glossary'.
My idea is to create posts for each term/word I want to explain (for example: 'blepharoplasty'), and use the content of the post to provide a description.
This works fine standalone with single post pages, and an archive to display all of them.
But I want to hook this into the rest of my site and automatically find any instances of my custom post titles in post meta data and the_content, and if found, to provide a link to the single post page.
I know a filter/hook is needed, but I have no idea how to write the conditions.
I think 121679 is somewhere along the lines, but I just don't know how to reference my custom post type, and how to search against the current post I'm using.
Can anyone help?
function bv_glossary_content_links($null, $object_id, $meta_key, $single ) {
// What conditions can go here?
}
add_filter('get_post_metadata', 'bv_glossary_content_links', 10, 4);
I have replaced my entity with Blog to explain better.
I have the following route:
Route::get('/blog-category', 'BlogController#showBlogCategory')
which shows a form with a dropdown of different blog categories and some other input fields related to the category
The form POSTs to the following:
Route::post('/blog-details', 'BlogController#showBlogDetails')
Here I validate the request the form and return back if there is an invalid blog category or if it is missing
This method is called showBlogDetails because the category and the other fields are passed on to the next view return view('blog-details', compact('blogCategoryData'))
In this view there is a form to fill in the rest of the blog details.
Both the blogCategoryData (each data has a hidden input field) and the blog details are POSTed to the following route:
Route::post('/blog-store', 'BlogController#store')
This is also validated using a Request but if it fails it tries to go back, which it can't do as only POST is allowed to get there.
I need the blog category fields before I can show the blog details and a Blog cannot be created without either stuff so I can't temporarily create one either.
This flow of selecting/filling in blog category fields and then entering details is a requirement so has to be done in that order, in 2 different pages.
So currently it is:
GET -> POST (validate) -> POST (validate)
What is the best way around this or how would I make my current flow work?
one way is to use javascript and of course ajax to fetch blog data and show corresponding section. first the page only shows categories drop down box. after changing that to a correct category page makes an ajax request and fetches data. then replaces it in a hidden 'div' and shows it.
another way is to bring replace the categories box in the previous page.
I have an meta_box in the post creation screen. As soon a user click on a specific category it will be displayed. For saving the information in the meta_box and post title and post content I use the hook post_updated. All is going to save fine in the database -- post data in wp_posts and the data in the meta_box into a special created table.
But sometimes the user want to edit this post from this 'special 'category. In this case the meta_box with the inserted information should be loaded and be editable. I know that I need to fill in the fields manually, but I need to know which hook is called when the user presses the edit link. An idea was, check for the url and if a parameter edit is found call my edit routine. But it looks like a dirty thing for me.
The codex is not very helpful. I tried the following hooks:
edit post, publish post, save post, wp insert post
But they are called after I pressed the actualize button.
BR,
mybecks
You don't have to use any hook for this, you just need to use following lines where you are generating your meta_box html
global $post;
now you have access the $post object when you are editing
get_post_meta($post_id, $key, $single);
use above function to get the value of particular meta and set it to your html as required.
for reading more about get_post_meta, goto http://codex.wordpress.org/Function_Reference/get_post_meta
I have a custom posttype in Wordpress 3. I would like to every post of this type to have the option to add a link. Basicly this will be a link that refers to another page/post whatever on the site.
There should be only one link for each post of this type. And i would then need to extract this link in my template files. Basicly im creating a post-type "Slideshow" And each slide-item should be connected to one page or post. So when you click a slide you will be taken to the defined page.
i know i can do this by using a custom-field. But then i would need to enter the whole url every time. I would like a feature similar to that of the wordpress WYSIWYG editor link button. So i can add a link to "existing content" easy.
Anyone know of any tutorials or similar on how to do this?
Thanks!
bit surprised no one has mentioned this plugin "Related Links"
Wordpress plugin Related Links
It adds a metabox to your edit forms. You can link to related content or put in external URL.
It allows links to posts, pages, media AND Custom post type - check its type on the Settings page of the plugin after install. It uses a similar search/browse facility to the normal WYSIWYG link insert feature!
What post-types does it apply to? If you are using on a custom post type, then check all the post-types you want to be able to link to - it still shows the box on this post-type itself.
It can accept multiple links, but one will work of course. Then you use the get_related_link() function in your template to output this and format as you like.
If you just want to make a link between the two posts, rather than insert it in your post content, I'd recommend the Posts 2 Posts plugin. It'll allow you to create links between posts without having to remember the full URL.
Edit:
I haven't used it, but I suspect the cardinality argument should help you limit the number of links - see the wiki.
And you can certainly access the connections in your templates - I have. Once you've registered your connection type, you can just call get_connected:
$venue_details = p2p_type( 'exhibition_to_venues' )->get_connected( $post->ID, array(
'posts_per_page' => -1,
'connected_orderby' => 'order',
'connected_order' => 'ASC' )
);
It seems to me that the best method to accomplish this would be to add a custom meta box to all posts and post types (see here:http://themefoundation.com/wordpress-meta-boxes-guide/). Within this meta box, you can simply query all posts that you would like to include in a dropdown. You can then select the post from that dropdown, obtain the ID of the post selected (use as data attribute in the option field), and then return the permalink for that ID. This will then allow you to simply select the post, rather than having to know the actual URL each time.
Another method would be to attach a piece of unique data to x post (most likely utilizing custom fields), and then also attach it to y post. In this way, you could use a function to automatically append the link to the displayed post. You would do this by querying the posts in the database, match the custom data, and if matched, display the link to that post. This would allow the entire thing to be automated, and you wouldn't even have to select anything. In my opinion, the title field should actually be sufficient for this, since both posts are different post types (you should be able to title them the same), and would likely make your query a bit easier/shorter since you would simply need to find the post that matches the title, and then link to the permalink.
I can elaborate on all of the above further, with code samples as well, but in my opinion, the question is slightly too vague to write a custom script example for this scenario.
I would hope the above would be sufficient to get you going.
I'm using a wordpress theme that allows users to create posts (they don't need to be logged in). The problem is that when the posts are displayed, <?php the_author(); ?> always shows as "admin". The post-creation form has a name field that I can get at in functions.php, but how can I manually change the author of the post to the name that was entered in the form field?
Without seeing the context, I can only offer a step in the right direction. Within a plugin or functions.php in your theme, you can call on the wp_insert_post_data filter to change the data that will be inserted as your post. For instance, if you wanted every post to be attributed to author with ID 5, you could do something like:
function my_change_author( $data , $postarr )
{
$data['post_author'] = 5;
return $data;
}
add_filter('wp_insert_post_data' , 'my_change_author' , '99', 2);
I've done something like this before where I have front end forms that I capture as posts and automatically assign to a predefined author that I call Web Monkey or something like that ;) Check out this page for more: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data. This filter is really powerful in that you can alter your data that will become your post in anyway before it hits the database.
Have you checked what the_author_meta() contains? WP has to attach a userID to each post, so chances are it's assigning user 1 to those posts regardless of what they're entering into the box. Without seeing the custom function or knowing what theme you're using to test, it'll be pretty difficult to troubleshoot.