Wordpress custom fields content don't appear when searched - wordpress

I'm using the plugin Advanced Custom Fields on a custom post type. When I enter in content into the custom fields and publish, all looks fine BUT when trying to search for words that are in a custom field it doesn't show up...
I really need this content to be searchable.
I'm displaying the custom fields using this code
<?php echo get_post_meta($post->ID, 'course-code', true); ?>
Can anyone help please.

Post meta is not included in WordPress default search. You could use a plugin like Relevanssi, which extends WP's search functionality.

Related

WordPress Page Templates for Custom Post Type

I have a custom post type, "Store Pages" for instance, which is an almost identical duplicate of the default Wordpress "Page" post type.
Like the "page" post type, I would like to create page templates (not post-type templates) and be able to select them from the "Template" drop-down within the "Page attributes" box in the page editor.
I have created several templates, but the drop-down menu does not appear; I am assuming this is because a custom post types does not allow support for this.
Is there a way I can create page templates for a custom post type without using "single-{post-type-name}.php" and having a dozen queries to load up different template files?
I have double checked the comments for the templates are correct as they appear when I create a new page (post type, "Page").
Help would be greatly appreciated.
starting 4.7 you can use the new feature described here https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
// … your code here
If I understood correctly you want a Select template dropdown for your custom post type.
You can do this easily through Advanced Custom Fields, here's a quick guide how to get through.
After installing the plugin you can access the Custom Field section, if you open it and click Add new it bring you to the field editor. Name it whatever you want, it's just for administrative display.
On Field type choose "Select", this will allow you to construct a select box on your backend, keep in mind the value of "Field name" you will need this later on the code.
Scrolling down you can add the values of the select box in the following format: "key value : Textual label" just assume for now you want 2 templates, one for audio posts and one for video posts.
If you keep scrolling down you can see the display rule for this field group, now you will have "post" and "page" by default, when you add different content types you will have the additional content types here to select, just go ahead and pick yours.
And, ta-da. If you go on the custom content type edit window you will find your new fresh select box here waiting for you.
The code integration now is very simple, just go onto your single-{post-type-name}.php template and pull the custom field data into your loop. Then you can use this to use get_template_part() to pull your custom templates.
<?php $template_type = get_field('template'); // This must match with the field name value ?>
<?php if (isset($template_type) && !empty($template_type)): ?>
<?php get_template_part( 'store', $template_type ); ?>
<?php else: ?>
// You should have a fallback for the all the existing posts without template set or if you create a new post without a template.
<?php endif; ?>
In this specific example the pulled template files will be in the format of store-{key-value-of-the-selectbox}.php, of course you can readapt that for you best convenience.

Custom location rules for custom post type in ACF

I've downloaded the ACF plugin for Wordpress and I am trying to add a custom location rule.
What I am trying to do is to get it to detect the categories used in a custom post-type. For this example, I have installed the WP-Knowledgebase plugin which uses a custom post type for the knowledgebase.
Does anyone know how I can get ACF to use the categories from this in my rules?
Maybe this help you.
To use in category.php
<?php
$cover = the_field('cover', 'category_'.get_queried_object_id().'');
// 'cover' is the name of custom field, replace this with yours.
echo $cover;
?>

woo commerce - how to show custom fields on published page

I have set 2 custom fields on the wordpress / woocommerce product page called "imballo" and "sottoimballo" with their values. How do I display these on the published page?
Thanks!
You would have to display the custom fields in the WooCommerce Single Product Page template,
You could do it in two ways,
Add a code in an existing hook of the Product Single page. Check hooks here
Modify the template by overriding it in your WordPress theme. Read here
And in the place where you want to display do the following,
<?php
//Please add your HTML structure as needed.
echo get_post_meta(get_the_ID(), 'imballo');
echo get_post_meta(get_the_ID(), 'sottoimballo');
?>

Woocommerce product form fields

I would like my product page that customers fill 5 text fields and choose 1 field type radio.
So my product page is a form where customers ask a question, fill some information and choose a paid option.
Like this french page => http://www.avocat-bervard.com/paiement-honoraires-consultation-juridique/
Is it possible with Woocommerce ?
If so, can you explain me how ?
Thanks.
You can create nice forms with plugin Ninja Forms :). Its a very cool plugin, with a couple of settings: sending emails, when submitting forms, etc.
It is also supports shortcodes, with this method you can implement your form on every single product page, or even display it in a widget area.
For widget area:
You need to enable shortcodes first in functions.php
add_filter('widget_text', 'do_shortcode');
Then call the shortcode in Appearence - Widgets
For template:
You need to edit the file where you want this form to display, single-product.php, meta.php :) etc.
To insert shortcode in template file you need to use the below code:
<?php echo do_shortcode( $content ) ?>

Display Custom Post Type within a page template in Wordpress

I am using custom post type plugin to create custom post types for my Wordpress website.
I want to add the custom post types to a page template. but, when I add the php loop to call the custom post type that I created, it calls the page content instead.
Does anyone know how to solve this problem? Thanks.
Try this before the loop:
<?php query_posts(array('post_type' => 'your-cpt-name') ); ?>

Resources