Subrata Sarkar
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: how to disable auto save post and revisionI added the following entries to
wp-config.php
of my application/* AutoSaving and Revisions */ define( 'AUTOSAVE_INTERVAL', 20000000000 ); // autosave 1x per year define( 'EMPTY_TRASH_DAYS', 0 ); // zero days define( 'WP_POST_REVISIONS', false ); // no revisions /* That's all, stop editing! Happy blogging. */
Then I started created a New Page in admin. Added a title and waited for a few seconds. When I checked
wp_posts
table I can see a new entry is added in spite of the above settings added towp-config.php
file.What I have done wrong?
I got the answer!
I can do it by setting the arguments like this:<?php $args = array( 'show_option_all' => '', 'show_option_none' = 'Select your language' 'option_none_value' => '' ... ); ?>
I got it to work finally! Everything inside the template page as you said. This is my updated code which worked for me:
<?php /* Template Name: Song Entry Form */ get_header(); if($_POST['post_submit'] == 'Submit') { $args = array( 'post_title' => $_POST['post_title'], 'post_content' => $_POST['post_desc'], 'post_type' => 'fav_songs', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed' ); $pid = wp_insert_post($args); add_post_meta($pid, "_song_artist_key", $_POST['post_artist']); } ?> <form id="post_entry" name="post_entry" method="post" action="<?php echo get_page_link('354') ?>"> <p> <label>Title</label><br /> <input type="text" id="post_title" name="post_title" /> </p> <p> <label>Description</label><br /> <input type="text" id="post_desc" name="post_desc" /> </p> <p> <label>Artist</label><br /> <input type="text" id="post_artist" name="post_artist" /> <input type="hidden" name="post_type" id="post_type" value="post_songs" /> <input type="hidden" id="post_action" name="post_action" value="post_action" /> </p> <p> <input type="submit" name="post_submit" value="Submit" /> </p> <?php wp_nonce_field( 'new_song_nonce' ); ?> </form> <?php get_footer(); ?>
+1 for WP community helpers! ??
Thanks for your reply. Because I am new to WP I did not understand a couple of things which if you please explain in a but more beginner way that would greatly help me to understand.
1. “You can hook save_post in the back end because the action is triggered when the post is updated or published by the main page’s script” – does this mean I should use this hook only when publishing a this custom post type from admin and not in front end script? If so, shall I only use
wp_insert_post
, grab the last inserted$post_id
and then runupdate_post_meta
against that ID? By the way, because I am trying to open this form for user inputs, meta information would only get added all the time, so shall I useadd_post_meta
instead?2. “I think if you just remove the function declaration wrapper everything will pretty much work” – I used (wild guess though) the function wrapper so that I can hook it against
save_post
. But from your above suggestion it looks like I don’t need a hook. The page will auto submit and do the insertion automatically. Am I getting this right?I will meantime try your suggestions and see how what happens. Regarding security measures, I will add those in the script as well. My first objective was to save the post with meta information and show theme in admin interface.
Regards,
Subrata SarkarThank you so much for taking time and correcting my error. Also sorry for a delayed reply. Changed my code per your suggestion and it worked!
Forum: Themes and Templates
In reply to: [Customizr] Add widget area before header (for advertisement)Thank you for finding the better way to do it.
Forum: Themes and Templates
In reply to: [Customizr] Add widget area before header (for advertisement)Hi, if I have understood your requirement correctly then you can try the following steps:
1. Create a custom plugin to display your content.
2. Create a sidebar and register it in your theme’s
functions.php
. Sidebar ID can be anything like ‘my-header-widget’.3. In your
header.php
write this code where you want your widget to appear<?php if(is_active_sidebar('my-header-widget')){ dynamic_sidebar('my-header-widget'); } ?>
Please let me know if this helps you!
I have finally got a solution but not sure if this is the best one!
This is how my function looks like now
function create_trip_package_map($post_id){ global $wpdb; $selected_packages = get_field('available_tour_packages'); if($selected_packages) { $wpdb->query('DELETE FROM ' . $wpdb->prefix . 'trip_packages WHERE trip_id = ' . $post_id); foreach($selected_packages as $package) { $table_name = $wpdb->prefix . "trip_packages"; $wpdb->insert($table_name, array( 'trip_id' => $post_id, 'package_id' => $package->ID )); } } } add_action('acf/save_post', 'create_trip_package_map', 20);
I referred to this article:
https://www.advancedcustomfields.com/resources/get_field/And then on my
tour
page I am running a custom query to retrieve records from my custom tablewp_trip_packages
usingget_the_ID()
of current tour.By doing the above I am now able to filter out only those package tours associated with current trip.
I believe there is a better way to do it but don’t know what it is. So please advise me the best way of doing this.
“draft_to_publish” resolved duplicate entries but it creates another issue now. The trip_id is being saved as 0, which means $id is not getting the actual ID value of the trip. How to get that with this hook?
And I am yet to figure out how to get IDs of relationship field (tour_package). Would you please tell me how I can retrieve ID of selected tour_package? Is there a better way to do this?
Hi,
I am back once again with new issue ??I created a table
wp_trip_packages
and with two columnstrip_id
andpackage_id
. I wrote the following function in myfunctions.php
file:function save_trip_package_relationship($id, $post){ //Code to insert mapping if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if (isset($post->post_status) && 'auto-draft' == $post->post_status) { return; } global $wpdb; $table_name = $wpdb->prefix . "trip_packages"; $wpdb->insert($table_name, array( 'trip_id' => $id, 'package_id' => 20 )); } add_action('save_post_trips', 'save_trip_package_relationship');
When I am adding a Trip records are getting added to the table however a few things I could not figure out:
1. Whenever I am clicking on Add New a new record is getting added
2. When I delete a post draft, a new record is being added
3. When updating a record is being added as wellI found the following two snippets by Googling but nothing is working
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if (isset($post->post_status) && 'auto-draft' == $post->post_status) { return; }
How can I prevent these duplicates to get saved in the table?
NB: From my previous message: “
$id
is the Post ID, i.e Trip ID but how would I pass the Package ID (e.g.$pid
) in the function” – please also help me with this. I explained the problem of getting relationship field ID in my previous post.Looking forward to your suggestion for one more time…
Thank you so much once again. Sorry for asking for one more help.
I am using Package post type as a Relationship field in Trip post type. How would I get the IDs of selected Package?What I have read so far I need to create a hook in
functions.php
so that when a post is added via Trip post type the function would trigger. What hook I should use here –save_post
like this?function create_map_on_save($id) { // Code to insert Trip ID and Package ID in the custom table } add_action('save_post','create_map_on_save');
What I don’t understand are
1. where to call this function from?
2.$id
is the Post ID, i.e Trip ID but how would I pass the Package ID (e.g.$pid
) in the function?Sorry for asking stupid question! I am fairly new to WordPress.
Hi catacaustic,
Thank you for your reply. The second choice makes more sense! One thing I did not understand though. You said ”
…a new relationship column where you store a package ID and a tour ID
Did you actually mean to create a new table instead with probably three columns like
MappingID
,TripID
andPackageID
?And if I create a custom table (never done that yet) I should be able to use
WP_Query
and use anInner Join
between three tables to pull data based on either aTripID
or aPackageID
?- This reply was modified 7 years, 10 months ago by Subrata Sarkar.
Forum: Requests and Feedback
In reply to: www.ads-software.com email notifications taking over my inboxI only subscribed to a topic a month ago which I don’t remember now! But getting tons of emails everyday from hundreds of different topics which I am not interested in! How I can tell WordPress to stop overflowing my inbox and only stick to the threads I am subscribed to?
I think there should be a way to know what topics I am subscribed to so that I can easily unsubscribe from those I no longer need to follow up!
Forum: Themes and Templates
In reply to: [Basic] Changing color of post titles on home pageThank you! ??
Forum: Themes and Templates
In reply to: [Basic] Changing color of post titles on home pageYou may rather create a separate stylesheet and create your own rule(s) to control this.
article.post h2 a{ color: #666666 !important; /* !important will override defaults */ }
To reference this new stylesheet you can directly put it into theme’s
header.php
or you can do it through theme’sfunctions.php
file by the following code snippet:function custom_resources_includes() { wp_enqueue_style('custom', get_stylesheet_directory_uri().'/styles/custom.css', array(), mt_rand(), 'all'); } add_action('wp_enqueue_scripts', 'custom_resources_includes');
Does this help?
- This reply was modified 7 years, 10 months ago by Subrata Sarkar.
- This reply was modified 7 years, 10 months ago by Subrata Sarkar.