How to save template data into wp_post table (post_content column)

Is there a way to save template data into wp_post table? I made a custom template that automatically makes tables and some sentences with the meta-data that users insert in. I wanted to make users choose a template and write in a standardized format with custom field. Users can now just put some text on my custom field (bottom of my post edit page) and click the template on the sidebar, then the contents show on the post page! And …
Category: Web

how load content as pop-up using ajax

There's a way to use ajax to load the content from single.php or a custom .php like ajax-single.php like this page does it: https://yellowimages.com/all/objects/apparel-mockups/ also like them show the URL from the post when you click on the link, I hope somebody can help me with this because I can't find a way to do it yet. EDIT 1: I use the next code on my index.php to load the post titles with the permalink: <div id="single-post-container"></div> <div class="wrap"> <?php …
Category: Web

Single post shows post three times

Not sure exactly what happened, but my site shows the single post content multiple times. Example. Reinstalling the theme didn't help. Also, it's not happening with any other theme, only with the current one. No plugins are active. Not sure what could be the problem.
Category: Web

Displaying Meta Box Image

I have some problems displaying info from my custom meta box in my custom post type single. I'm using Reusable Custom Wordpress Meta Boxes by Tammy Hart. I'm able to display the textfields using this: <?php echo get_post_meta($post->ID, $prefix.'hjemmeside', true); ?> But I can't get the image to display, instead DEBUG is telling me that it is an "Undefined variable: post_meta_data in". Currently I'm using this script: <?php $custom_image = $post_meta_data['image'][0]; echo wp_get_attachment_image($custom_image, 'thumbnail'); ?> Is this wrong? ID for …
Category: Web

Two single.php files?

I have a custom post type "people". For each person, I can enter the following custom fields: "address", "occupation" and "pictures". In the single-people.php I display the address and the occupation. In addition, this single template contains a gallery button - when the website user clicks on it I want to takes the user to a separate page where only the pictures of the person he just looked at are displayed. How do I achieve that? I cannot just create …
Category: Web

Post Template Query with WP_Query?

I've seen this solution for querying pages based off of template type: Page template query with WP_Query I'm having trouble getting it to work with posts, that are using a "Single Post Template:" rather than a "Template Name:" definition. Here is my code: // query $the_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_wp_page_template', 'value' => 'single-current.php' ) ) )); Is there a different 'key' I should be using? Something like …
Category: Web

How to display different blocks for mobile and desktops

I want to display a fixed banner from the bottom left of the screen. But at the same time, the banner is different for desktops and mobile devices. Please tell me. How can I determine the user's device? For this, can I use the wp_is_mobile function? As I understand it, wp_is_mobile identifies the device by the user agent of the browser. PHP code is very simple. Something like the following? <?php if (wp_is_mobile()):?> <div class="mobile_banner"><img src="mobile.png"></div> <?php else:?><div class="desktop_banner"><img src="desktop.png"></div><?php …
Category: Web

Need post_type_archive_title function but in 'single'

I'm trying to pull a custom post type name/title out for use in the breadcrumb of a single-[cpt].php template file. In the archive-[cpt].php I can use post_type_archive_title() and it echo the name. How would I get this same title in a single view? Thanks! I've trawled though the codex and haven't seen a function, but might have missed it!
Category: Web

Single page not working for custom post type

I created a custom post type with the following code: add_action('init', 'create_trans_career'); function create_trans_career() { //Arguments to create post type. $args = array( 'labels' => array( 'name' => __('Career', 'trans'), 'singular_name' => __('Career', 'trans'), 'add_new' => __('Add New', 'trans'), 'add_new_item' => __('Add New Career Item', 'trans'), 'edit' => __('Edit', 'trans'), 'edit_item' => __('Edit Career Item', 'trans'), 'new_item' => __('New Career', 'trans'), 'view' => __('View', 'trans'), 'view_item' => __('View Career', 'trans'), 'search_items' => __('Search Career', 'trans'), 'not_found' => __('No Career item …
Category: Web

Give active class to current page on a while loop WP query for custom post types listing

I have a single-programs.php page and at the top of this single page I need to list all the entries from the custom post type "programs". Is there a way to give "active" class to this list for the current page (current single post type" ? Here is my code: <?php $args = array( 'numberposts' => -1, 'post_type' => 'programs', 'order' => 'ASC' ); $the_query = new WP_Query( $args ); ?> <?php if( $the_query->have_posts() ): ?> <ul> <?php while( $the_query->have_posts() …
Category: Web

Wordpress - When visiting a `single post/ single.php` my category menu item link becomes active

I'm new to WordPress. So, I'm not really sure if it's normal behavior or not but this is bothering me. So, I've my main navigation menu consists of Home | category_1 | Category_2 | Category_3 ... The issue is that whenever I click on a post link it loads as expected but the category under which the post is created also becomes active which I don't want. For example, if I click on a post from category_1 it loads with …
Category: Web

How to disable the single view for a custom post type?

Given this custom post type: register_post_type( 'sample_post_type', [ 'labels' => [ 'name' => _x('Sample Posts', 'post type general name'), 'singular_name' => _x('Sample Post', 'post type singular name'), ], 'public' => true, 'show_in_nav_menus' => false, 'exclude_from_search' => true, ] ); How can I disable the single post view for this particular post type? Displaying a simple 404 is fine, or redirecting to the homepage. Since this is a plugin, I can't create a single-sample_post_type.php file to set up an empty page.
Category: Web

LinkedIn Share Post Button

Hi there I have been having trouble with a LinkedIn custom share button. My theme didn't seem to provide one and I like this theme so wanted to create my own. I have gotten as far as getting a window to open that signs you in to LinkedIn and takes you to post about something, I just can't get the code to work so it also inputs the URL of the WordPress single post you are currently visiting. Here is …
Category: Web

Custom SQL query to get List of posts with featured image url

I am working on a task where i need to retrive 100s posts under single-page/single-request with their featured images. By using wordpress method of retriving posts and then retrive featured image individually using get_the_post_thumbnail function it takes so much time to load the page. Can someone provide a faster solution for this like retrive posts and featured image under one single query. That should speed up the proccess.
Category: Web

Shortcode and get_template_part

I'm developing my own plugin for my wordpress. I create a shortcode for my plugin and CPT with a custom taxonomy and custom single-CPT. When I try to use the function get_template_part() in my shortcode, the result is a call to a single.php template from the theme. How I can limit where get_template_part can look for files? This is my shortcode: function shortcode_display_products ( $atts ){ global $wpdb; $query = ''; $atts = shortcode_atts( array( 'categories' => '' ), $atts, …
Category: Web

Creating a Back button on detail post page to go back to blog page with same query strings and page id

So, I would like to have a back button on the single post page that can be dynamic to the point to where it knows where it is in the query and bring me back to the blog page on the right page number and category and search query string. For example -> "localhost/news-blogs/page/3/?s=news&nb-cat=16" Now I can do this wp_get_referer() If was to stay on that page, but if I click on the next post link then it would just …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.