I had given a rest to this problem and returned it back today with a fresh mind.. I noticed that the problem is about file upload function.. I revised the code as below:
$attach_id = media_handle_upload( $file_form_handler, $post_id );
if ($attach_id != false){ // if the attachment is loaded, register them as post meta
$file_load = update_post_meta($attach_id,'_wp_attached_file',$files['name']);
$attach_data = wp_generate_attachment_metadata( $attach_id, ABSPATH."media/".$files['name'] );
$file_load = wp_update_attachment_metadata( $attach_id, $attach_data );
if ($file_load == false) {
$notice = __('An error occured while setting the post meta for the uploaded file.', TDOMAIN);
} elseif ($file_load == true) {
$notice="OK";
}
} else {
$notice = __('An error occured while uploading the file.', TDOMAIN);
}
Related Posts:
- Generating and downloading files with WP API
- wp_redirect to file:// location results in blank page/cannot be displayed page
- Conditional tag only for front of custom post type
- FacetWP paging custom wp_query
- why post_class() function apply css classes to all other files?
- Update post if exist from PHP
- Remove taxonomies using register_post_type_args
- Looping Through Categories of a CPT
- Different options per post type in WP_Query
- How to create connection among state, city, store and store number based on URL
- How to add a sub directory to WordPress single posts without affecting other post types?
- Custom post type and standard post not displaying or working
- Change custom taxonomy archive permalink
- What is the diference between Post Metadata and Queried Object
- post_type internal ID?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- REST filters only firing when I have a param set
- Is it possible to have “two” sets of tags?
- How do you make a list and list item relation if custom post types?
- How to enable UX builder for custom post types in Flatsome
- search custom post type by custom fields on front end
- Show Taxonomies with admin area for custom post type?
- Custom post type Shortcodes wordpress
- category list with cutom post count
- Empty search input does not return all posts
- How to properly rewrite pagination rules for a CPT to avoid 404 error on /page/2
- After creating Custom post type by user delete old one
- WordPress admin display post type tags as checkbox
- I want to know if i can add two different custom post types to my wordpress site
- SEO Concerns With Rewrite Rules
- Empty taxonomy items for CPT in admin grid
- $post->post_meta not pulling any post in wordpress/php
- How to show my post type TEAM in dynamic way?
- Set parent for custom post type archive rewrite url
- WordPress custom API endpoint – how to make the request more flexible
- Values from meta-box not on $_POST
- How to rewrite the beginning and end of the permalink structure in a custom post type?
- Add to ‘action’ within post.php to allow more actions when editing a Custom Post Type in a plugin
- How to get_term_meta on single custom post?
- custom endpoints on Custom Post Type return 404 page not found
- Search Filter CPT, Custom Loop
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- ArgumentCountError caused by wp-includes/class-wp-hook.php
- ajax response not recieving
- Reordering admin columns for CPT with custom taxonomy and an added custom field
- Getting post attchment URL to populate a CPT Admin Page Column
- The Difference Between Categories and Tags and Taxonomies and Terms
- How to build a WordPress post review system beside commenting
- Pagination doesnt work in custom post type
- Route subpage to Custom Post Type
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- Archive links for custom post types
- singular_name label in custom post type
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- Many to many to many custom post relationships
- how to create custom post type with dynamic category_name using shortcode
- How to get dropdown instance value in WordPress custom Widget
- page template as a custom post type archive page
- Use core block functionality in a custom block gutenberg
- Which escaping function should be use on register_post_type label?
- widget_posts_args not using the number of posts in widget
- Add form after woocommerce admin order edit
- Show All Custom Post Types On A Single Archive Page
- Include custom post type custom taxonomies in Categories widget
- Show message when query has no posts
- Template Hierarchy for custom post type pages
- Display message if no posts in Custom Post Type loop
- Unable to edit categories in custom post type
- gutenberg message
- How to sort a WP_Query by a custom field AND ALSO filter by a different custom field
- Get category if used in a custom post type
- Iterating through Object Array to customise display of full custom taxonomy for custom post type
- Sort custom post type by most current date picker
- Return number of all custom posts type by author in all statuses
- I can no longer post or even save a draft, getting the error “A post type mismatch has been detected.”
- Get taxonomy term by slug in post on archive page
- WP_Query of custom post type sorted by meta_key has unexpected results
- Displaying custom fields for custom post type generate with Custom Post Type UI Plugin
- WordPress hook after post content and meta update
- Query not work for current taxonomy
- Using menu_position to add two entries between Dashboard and Posts
- Custom Post Type “MUST NOT” be able to search via URL
- I am trying to get cutom post cout by month of current taxonmy term
- When updating non-public custom post type it says “Post updated. View Post”
- How to show all taxonomies within custom post type loop
- Showing taxonomy terms on custom post type
- Create short URL with auto 301 redirect
- Custom taxonomy template list not working (404)
- Published post auto change status to pending after 90 days
- How to retrieve all wordpress posts (specific type) inside a function in php?
- Add shortcode inside of the_content()
- Create a page by importing data from an XML file ( On clicking a button inside admin options page)
- Showing User’s Post Counts by Custom Post Type in the Author.php?
- Should Custom post types and fields be in the theme files or in a custom plugin packed into the theme?
- ACF for custom post type archive pages: which hook to use?
- How To Post WordPress Custom Post Types to Twitter via IFTTT
- Custom Post Type Category URL
- Want a custom query with just one category but from all custom post types
- Pagination hitting 404 page on /page/4
- Convert comma separated list to serialized array to import as post meta