Tag Info

New answers tagged

0

Use this code for solve your Problem. function custom_help() { global $post_ID; $screen = get_current_screen(); if( isset($_GET['post_type']) ) $post_type = $_GET['post_type']; else $post_type = get_post_type( $post_ID ); if( $post_type == 'listing' ) : $screen->add_help_tab( array( 'id' => 'you_custom_id', // unique ...


0

I solved it using the following WordPress Plugin, which has plenty of options to customize: https://wordpress.org/plugins/jquery-collapse-o-matic/


0

If you save $jobcatsvalue make sure if it's an array of integers when saving. // Format the taxonomies if(is_array($_POST['jobcats'])){ foreach($_POST['jobcats'] as $j){ $jobcatvalue[] = intval($j); } } else { $jobcatvalue = array(intval($_POST['jobcats'])); }


-1

Use this code for access first post. if( $wp_query->current_post == 0 && !is_paged() ) { /*first post*/ }


1

As of PHP 5.4, you can directly dereference an array, so to get the first term, you can simply do. $first_term = get_the_terms( $post->ID, 'TAXONOMY_NAME' )[0]; var_dump( $first_term ); If you need a specific property (say the term name) of the first term, you can do the following $first_term_name = get_the_terms( $post->ID, 'TAXONOMY_NAME' ...


0

how about directly access the key of object? $terms = get_the_terms( $post->ID, 'sitecat' ); $first_term = $terms[0]; so you can access the object. echo $first_term->name;


0

Here is how i accomplished this.. Inside of the admin_menu action, I added a submenu item to the parent menu item ('nwcm') with the URL parameter of the taxonomy edit page. add_submenu_page('nwcm', 'News categories', 'News categories', 'edit_posts', 'edit-tags.php?taxonomy=nwcm_news',false );


3

Always great if someone wants to use better, more correct and more efficient ways to get things done. To achieve what you need is not difficult. WORKSFLOW: Use the usort() to create your custom sort order Use the the_posts filter to sort and return the sorted array of posts just before the loop is executed Inside the loop, all you need to do is to ...


0

I used your first snippet of code and it helped me out a lot with the Sahifa Theme. Like you, my nav was disappearing on the custom post pages. After analyzing the code I realized that the following line: $post_type = get_query_var('post_type'); Was not including the other standard posts & pages when it was on the post_type pages. So I changed it ...


2

If I understand the question correctly, you want to produce something like this: Sub-Item 1 Post 1 Post 2 [...] Sub Item 2 Post 1 Post 2 [...] There may be a more efficient way than what I am about to tell you, but I would try something like this: First create an array to hold your sorted posts. $sortedPosts = array(); Next, create an array for ...


1

The function you are looking for is wp_update_post(). You would want to have your posts which you want to update, then set up a loop to update each one individually. // However you get your posts, ID's, etc. $posts = get_posts( array( 'post_type' => 'post' ) ); for ( $posts as $post ) { wp_update_post( array( 'ID' => $post->ID, 'post_parent' ...


0

Remove line#5 and do the following: if ($query->have_posts()) : echo '<h2 class="seccion col-sm-12">Tour</h2>'; //we are showing the div inside the conditional I removed unnecessary <div>, as <h2> itself is a block element and can do the trick for you.


3

Solution from a cross post over at StackExchange from @birgire: The problem is that you run the clientarea_default_order callback too late. To fix that you only have to change the priority from the default one that's 10: add_action( 'pre_get_posts','clientarea_default_order'); to the priority of 9: add_action( ...


0

Your main issue is here is date formatting. Although the other answer will work, it is ineffecient and will cause inconsistant amount of posts per page in paginated queries. The issue here is, if you have 100 posts and only 10 has a date in future, you are wasting a lot of resources querying an extra 90 posts to just skip/hide them in the loop. Also, if you ...


1

You have one or two issues here and possible future bugs that you might encounter term in your tax_query should be terms Be carefull with terms having dates as names and especially dates as slugs. This can cause issues and unexpected results if custom permalinks clash or if something falls into the template hierarchy for some reason. Never use the name ...


0

I have found a SOLUTION!!! (After endless research.. I can have CUSTOM POST TYPE permalinks like: example.com/category/sub_category/my-post-name here the code (in functions.php or plugin): //===STEP 1 (affect only these CUSTOM POST TYPES) $GLOBALS['my_post_typesss__MLSS'] = array('my_product1','....'); //===STEP 2 (create desired PERMALINKS) ...


0

Jeroen your Quection is Custom post type Event display but old Event not display so you can use this code Please insert your meta value date and and current date to strtotime to check date is today or not condition. <?php $YOUR_CURRENT_DATE = date('d-M-Y'); $args = array( 'post_type' => 'event', 'posts_per_page' => -1,'orderby' => 'menu_order ...


1

You are almost there. You just need to use wp_mail to send emails containing in your array. Here is how you can achieve that using save_post action hook. /** * To send email on updating your event post * * @param int $post_id The post ID. * @param post $post The post object. * @param bool $update Whether this is an existing post being updated or not. ...


1

By passing the _builtin argument to get_post_types(), only WordPress default post types will be returned. Instead, just pass public as an arguement, Here's an example of output on a development site with WooCommerce activated: var_dump(get_post_types(['public' => true])); //result array(4) { ["post"]=> string(4) "post" ["page"]=> ...


0

i.e. register a custom taxonomy MY_NEW_CARSS for custom post types: $my_taxon_name = 'MY_NEW_CARSS'; $my_post_types = array('SUB_CAT_1','SUB_CAT_2','SUB_CAT_3'); //REGISTER CUSTOM TAXONOMY ( http://codex.wordpress.org/Function_Reference/register_taxonomy ) //If you aim to register HIERARCHICAL(Parent-ed) post type, read this warning: ...


0

The solution to this was pretty simple.Had I read WP documentation thoroughly for get_categories Apparently I had to set this 'hide_empty' => false when I fetched my taxonomies :)


1

Yes because your code has syntax error. It should be this. if ( is_singular('my_cpt') && ( has_term( 'myterm', 'mytaxonomy', $post->ID ) ) ) { } Did you notice if condition should close just after is_singular('my_cpt').


0

I found the answer myself - so here is the update to above problem: Custom post type registration: function create_post_type_mycustomname() { $args = array( 'capability_type' => 'post', 'has_archive' => 'mycustomname', 'rewrite' => array( 'slug' => '/mycustomname', 'feeds' => false ...


0

I think the best option would be is to use your getPostViews() count and incorporate a system in there to append the trending term to the post once your counter hits 150. Here is our worksflow Get the post view count (which you are already doing) Compare the current count to the desired 150 Use wp_set_object_terms() to append the trending term to the ...


0

just to answer the second part, the syntax is: example.com/tag/blue?post_type[]=custom example.com/tag/blue?post_type[]=post or for multiple types: example.com/tag/blue?post_type[]=custom&post_type[]=post


1

Use get_terms() to get the child terms of a given term. You need to feed the specific term id to either parent  (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string. OR child_of - (integer) Get all descendents ...


0

Eric based on your code I wrote to meet my needs, for those who want to follow: Eric com base em seu código eu escrevi o para atender as minhas necessidades, para quem quiser segue abaixo: <?php global $wpdb; $produto_id = 22777; // ID do produto $consulta = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_itemmeta woim LEFT JOIN ...


1

Before I start, you have a bug in your code which you should have picked up if you had debug turned on. You are first assigning $r['cat'] to a variable before even checking if $r['cat'] is set. Because cat is not a default, it may not be set, which will cause a PHP error when cat is not set. You can refactor your code to something like this: (Requires ...


1

You have a lot of issues here: You should not be using $_GET variables without sanitizing it. Never ever trust any user inputs and URL parameters. They might contain malicious code which can harm your site. To sanitize and validate a $_GET variable, use the filter_input php function $filtered = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING ) ...


1

1.Login as the admin in WordPress. 2.Go to the Settings tab. 3.Go to the Reading tab. 4.Change the Blog pages show at most from the default 10 to any number *less than 10. For example, 5. 5.Save the changes. 6.View the blog. Hope that helps.


0

The custom query to get custom post type posts filtered by 2 different terms from 2 different taxonomies will be: $args = array( 'post_type' => 'listing', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'job_listing_region', 'field' => 'slug', 'terms' => ...


0

After some research, I found that Custom Post Types don't store post_parent for attachments or may be requires some tweaking with register_post_type(). However, I found that when uploading attachments to regular posts, WordPress sends a post_id with AJAX and same is not happened with Custom Post Types. So, we need to assign post_id to Custom Post Type media ...


-1

Create custom post type by writing below code in function.php file located in Apperance => Editor . This code is very simple example of custom post type. // custom post type function function create_posttype() { register_post_type( 'movies', // CPT Options array( 'labels' => array( 'name' => __( 'Movies' ), ...


0

Just don't use the action save_post, use "save_post_{$post->post_type}" instead. It fires right before save_post, and you get the same information. Example for the post type masters: add_action( 'save_post_masters', 'my_custom_slug', 10, 2 ); function my_custom_slug( $post_id, \WP_Post $post ) { }


1

do_shortcode([espro-slider id=21]) will process the shortcode and return the result. The Codex describes exactly this example: // Use shortcode in a PHP file (outside the post editor). echo do_shortcode( '[gallery]' ); You can often just call the callback directly also: function generic_shortcode_callback($atts,$content) { return "Yay! ".$content; } ...


2

You can change it via the category template (if you have multiple category templates you'll need to edit all of them; if you have archive.php, you need to edit it only there). Otherwise you can use the Yoast SEO plugin which have settings for naming the archives (actually I think that almost all SEO plugins have those settings).


1

We will use a small piece of the logic from my previous answer in this appraoch. We need to do the following: Get an array of post ID's from the query we have run to get our post limit of 100 Use the current post ID and search for that specific post ID in the array of post ID's Use the array key where our values match, add 1, and return that as our rank # ...


0

Ok, an answer to all. First, thank you for you help. Anyway, none of your solutions really address my issue. I don't like custom links on nav menus, at all. And that's because they're not dynamic, you cannot build them dynamically. So when you move the site and change url (for example, from staging to production) you'll have to remember to manually change ...


2

Have a look at post_class(). Check if the theme using it (every good theme should). If so then you can use post_class filter to add appropriate classes to the container. Here is an example how you can use that filter add_filter('post_class', function($classes){ if(!is_singular('song')) return $classes; $additional_classes = ...


0

Feito! Realmente com o WP_Query não dá... pra saber essa informação é necessário utilizar 2 tabelas do WooCommerce. Então montei a função pra você... ela busca pelo postID do produto e retorna o objeto dos pedidos pra você fazer o loop normal. É só coloca-la no seu function.php e usa-la em qualquer lugar que quiser! Aqui funcionou bem! Se algo der errado ...


0

Using plugins like Paid Memberships PRO or s2member would be easiest solution for your purpose. You can create new user group and there capabilities. After that you can select which user group can see your post.


3

Reviewing the MySQL string functions, it looks like you could use the SUBSTRING_INDEX() function: ORDER BY SUBSTRING_INDEX( p.post_title, ' ', -1 ) {ASC|DESC} LIMIT 1 to order by the last word of the post title. You could test this method within your orderby filters. Example: Prev/Next CPT - ordered by last word in post title This is an example how ...


0

Just create an archive-{post_type}.php when you create a custom post type and include this function: flush_rewrite_rules(); Make a page of your custom post type. It's called an archive page.


0

All I can think is to process the posts at an earlier stage with a Core hook. This is crude, of course, but: function hack_the_post($posts) { foreach ($posts as $p) { $p->post_content .= ' I added this'; } return $posts; } add_action('the_posts', 'hack_the_post'); It is a bit energy intensive but so long as your plugin/theme uses more or less ...


2

Custom post type archive page does not need "dumb" Page. In fact, there could be the culprit. You should try this: Remove /* Template Name: Staff */ from archive-staff_member.php (not needed) Remove "dumb" stuff Page (if created). There could be some permalink conflict. Go to Admin > Settings > Permalinks and re-save it (it will regenerate rewrite rules) ...


0

Yes, the function is_post_type_archive only works in archive.php To have an item on nav menu links to your staff_member, you will add a custom link menu item in stead of a page whose template is your file tempate. The URL of that item will be got when you vardump this: get_post_type_archive_link('staff_member') And to custom the performance of the ...


0

Just to check the basics first: have you already gone into 'Screen options' at top right? After you click that tab, is your custom post type listed there with a checkbox? If not then you know it's something in the code (if it's there unchecked, tick the box and it should appear in edit page).


-1

After two days with this problem have resolved the problem, I fix it adding tax_query parameter with my taxonomy name and slug of the category requested: $args = array( 'post_type' => array ( 'servicios' => 'servicios', ), 'tax_query' => array( array( 'taxonomy' => 'category', ...


0

Don't use query_posts Create a new WP_Query or use pre_get_posts to modify an existing query. $args = array( 'post_type' => 'servicios', 'category_name' => 'category-name' ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { ...


0

I found a solution which displays the posts ordered by the date value, and also removes the past ones. <div class="container"> <div class="row"> <table> <tr> <th>Artista</th> <th>Fecha</th> <th>Ciudad</th> <th>Información</th> ...



Top 50 recent answers are included