Tag Info

New answers tagged

1

get_post_custom isn't a great function if you're trying to get values that are serialized, you have to unserialize them yourself. A better function is get_post_meta: $options = get_post_meta( $post->ID, 'photo-artist_tfuse_post_options', true ); echo $options['photo-artist_seo_description'];


0

If I'm understanding correctly, you want to use your own select form to update a post's published status instead of the publish/unpublish buttons? Something like this would work for that: function save_my_data($post_id){ if($_POST['publish'] == 'yes' && get_post_status($post_id) != 'publish'){ //whatever your post variable is ...


2

I don't know if it is a typo, but your custom post type name is incorrect, it cannot have spaces, and also you should just use underscores to separate names in custom post type names register_post_type('blog posts', $args ); Is it just blog or blog_posts In your query in your widget, you are querying the custom post type blog, which does not match your ...


1

I have managed to resolve this by adding in a custom rewrite into the functions file: // Add custom rewrite rules to handle things like years in custom post archives function add_rewrite_rules($aRules) { $aNewRules = array( 'news/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?$' => ...


1

Your problem is your naming convention. Look at the Template Hierarchy. The archive- prefix is reserved for date and custom post type archive pages. You are using this as prefix to a page template This is not only confusing to humans, but to Wordpress as well. For page templates you should be using the page- prefix. Just a note, as from version 3.4 you ...


1

First, your filter should return, not echo anything. The content will appear in the wrong place if you echo directly within the function. The original contents of the_content are passed to the filter function as an argument- function fds_the_content( $content ) { // <--- original value of the_content // append original $content $new_content = ...


1

"Page not found" means it is not a template problem, rather permalink issue. Try setting your permalink to default and than visit the page!


0

Try visiting : http://mywebsite:8888/about-us/news/2015/03/ You are using slug => 'news' so 'client-news' will give you an error


0

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $args = array( 'post_type' => 'product', 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => 'price', 'terms' => $term->name, 'field' => 'name' ), ), ); ...


2

I think that the function you need is wp_trim_excerpt. With this function you can generate a excerpt from any text: $text = "Some context"; $excerpt = wp_trim_excerpt( $text ); It is important to note that wp_trim_excerpt use the excerpt length set by WordPress, that is 55 words by default, and make use of excerpt_lenght filter, so it will work with any ...


0

change your $args array to the following $args = array( 'post_type' => 'product', 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => 'productcategories', 'terms' => $term->name, 'field' => 'name' ), ), );


1

Got help on Facebook and just needed to change this: <option value="<?php echo $term->name; ?>" <?php if($_POST['mealtype'] == $term->name) { echo 'selected'; } ?>><?php echo $term->name; ?></option> to this: <option value="<?php echo $term->slug; ?>" <?php if($_POST['mealtype'] == $term->slug) { ...


0

You can use the month parameter of WP_Query to get posts by month. For example, to get all posts published on March, ignoring year: <?php $the_query = new WP_Query( 'monthnum=3' ); echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; ...


0

An alternative solution is to use WP REST API: http://wp-api.org/ If your custom post type uses custom fields, the RESP API saves you the trouble of including the custom fields in the RSS.


1

Have you tried add_theme_support( 'title-tag' ); And remove the title tag from your theme, and call the wp_head() at proper place.And let wp handle the title tag for you.


1

I have done custom post type with multiple content editors ready to translate, I have used This Metabox Plugin to add the meta boxes, this plugin allows you to create multiple meta boxes according to the theme requirements, to achieve your requirements, 1st install this plugin Here is the link Then add code as follows in your functions.php or separate file ...


2

There's no way to set this text directly. But, the "Empty Trash" text is run through the translation API before display. You can hijack this translation to replace the text with your own string. get_current_screen() is used to check the post_type of the current admin screen, so you can make sure you're only affecting your "task" type's screens. add_filter( ...


0

This is an update of Stephen's answer based the new get_terms_by function and assuming we know what taxonomy we want. add_action('set_object_terms','save_terms',10,6); function save_terms($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) { //Assuming we only want terms from specific taxonomy //If not simply remove this conditional ...


0

Your second function is wrong. get_post_type($post) excepts the current post object or post ID or any post object or ID given to it. You are using the arguments for get_post_types( $args, $output, $operator ) for get_post_type, which fails the function which in turn gives you the error in your foreach loop. To rectify your function, use something like this: ...


0

Slightly hard to follow you here, but from the file you posted there is a line: $excerpt = implode(" ",$excerpt)."..."; Change it to: $excerpt = implode(" ",$excerpt); Edit - Corrected line, should work now.


0

You can add the following code to your function.php, I Never test this but I believe it should solve the problem for you. One thing you needed to do while making use of the code is to change the custom-post-type1... to the name of your own CPT. function add_my_CPT( $query ) { if( is_category() || is_tag() && empty( ...


1

My solution to this problem when extending the Walker_Nav_Menu was to skip check if current_page_parent when C.P.T. I identified C.P.Ts following this stackexchange post. This does not entirely solve the problem as I am using current_page_item for C.P.T parent menu items, but it does achieve the desired outcome. Here is my class. class My_Menu extends ...


0

Custom post type archives don't have year/month rewrite rules, they only have a single archive which will be at /press/ and /more_posts/. If you want those, you'll have to add them yourself. For the taxonomy, add the taxonomies argument to your post type registration to insure the two objects are connected, see the note about this on register_post_type.


0

It doesn't seem to be a WP Network main object for getting data from other sites in the Network i.e. $wp_network->site1->get_post_type('events'). I solved this using the automatically generated RSS feed for the custom post type. The feed is available on /[custom post slug]/feed How to read the data from other WP sites WP comes with SimplePie for easy RSS ...


2

You should be able to provide the slug of your top level page (admin.php?page=my_page) when registering your CPT(s): register_post_type( 'matches', array( 'labels' => array( 'name' => __( 'Matches' ), 'singular_name' => __( 'Match' ) ), 'public' => true, 'has_archive' => true, ...


1

First, let's change your <title> to <title><?php wp_title(' | ', true, 'right'); ?></title> Because adding to the title string in that was isn't very future-forward, instead it's best to use a filter to do any modifications to the title. So let's instead ad (in functions.php): add_filter('wp_title', 'my_custom_title'); function ...


1

You may want to filter out the title. add_filter( 'wp_title', 'wpse179527_wp_title' ); function wpse179527_wp_title( $title ) { global $post; if ( is_single() && 'custom-post' == get_post_type( $post ) ) return ''; return $title; }


0

The Posts to Posts plugin will allow you to define relationship metadata in the way that you describe.


0

If you're in the single custom post template, you can get the terms that the post belongs to by use of $terms = get_the_terms( get_the_ID(), 'btp_work_category' ); Then you need to determine parent term and display it with its children. The code below assumes that the post belongs to one top category (term) and the taxonomy tree has no more than 2 ...


1

For anyone else having this issue - the working code looks like this (placed in the functions.php file): function default_post_type($post_id) { if (in_category('YouTube')) { set_post_format($post_id, 'video'); } } add_action( 'publish_post', 'default_post_type' ); Happy WordPressing


0

I'm also wanting the post to be assigned the post type "Video". You can't just change a post to a different Post Type. There is a difference between "Post Type" and "Post Format". From your examples I assume you would like to change the "Post Format", as per the codex http://codex.wordpress.org/Function_Reference/set_post_format, you would need to ...


0

This line doesn't look right: $campaign_email = get_post_meta( $_GET['pid'], '_campaign_email', true ); Try: $campaign_email = get_post_meta( $post_id, '_campaign_email', true ); EDIT - Typo.


0

I found the solution. function add_rewrite_rules($rules) { $newrules = array('cpt-slug/([^/]+)/([^/]+)/?$' => 'index.php?name=$matches[1]&post_type=cpt_name&member_view=$matches[2]'); $rules = $newrules + $rules; return $rules; } You just need to change 'p' to 'name'


0

ok, I fixed (with the help of everybody, from Reddit, and StackExchange), I had several issues. This is my working code: $args = array( 'numberposts' => 1, 'post_type' => 'my-cpt', 'order' => 'ASC' , 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'end_date', 'value' ...


1

Your issue is not with storage, it is with retrieval. get_post_custom() is inconvenient and rarely used in practice. get_post_meta() is more common in practice. Note it has explicit argument to retrieve a single value, rather than array of values for a key (which WP can do too).


4

Welcome to WPSE Ittikorn! Sometimes it is the easiest to just look right at the source. There even is a link right at the bottom of the Codex page you linked: https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/link-template.php#L1112 There you can easily see that there actually is a filter called post_type_archive_link So to give you an ...


4

Just look at the source of get_post_type_archive_link(): return apply_filters( 'post_type_archive_link', $link, $post_type ); Sidenote: The function uses home_url(), which is a wrapper for get_home_url(), which offers another filter: return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); that runs earlier. With "pretty permalinks" ...


3

The filter is post_type_archive_link, defined (WP 4.1.1) on line 1112 of file wp-includes/link-template.php: apply_filters( 'post_type_archive_link', $link, $post_type ); And the use: add_filter( 'post_type_archive_link', function( $link, $post_type ) { //Do something return $link; }, 10, 2 );


0

You did not specify a taxonomy term in tax_query. It should go: 'tax_query' => array( array( 'taxonomy' => 'taxonomy_name', // my guess 'field' => 'name', 'term' => 'Term name' ), ), I prefer using 'field'=>'slug' in such cases as term names are more likely to be changed. And also change order by 'title' to ...


0

THe only possible way is this if your html input name is name="end_date[]"... SO can you please check it once more


2

it looks as already answered here on stackexchange (really detailed way), as first you can try: add_filter('soto_property','qtrans_convertURL'); Anyway, have a look here on qtranslate slug plugin, usually it save tons of troubles. And small note - if I were you, I would better use mqTranslate (which is based on qTranslate, but it's compatible with last ...


1

Before amending $query we first have to find out which posts to exclude, which requres two querys (if I can think of a way of doing it in one I'll update the answer). The first will grab a list of distinct ID's of all parent events, for example - SELECT DISTINCT wp_posts.post_parent FROM wp_posts WHERE wp_posts.post_type = "event" AND wp_posts.post_type = ...


3

To be really honest here, that is a useless parameter when used with custom taxonomies, as custom taxonomies are already registed to a custom post type when they are registered. Using the taxonomies parameter, you are re-registering a custom taxonomy to the custom post type As stated by the codex, the taxonomies parameter is used to register build in ...


1

the_ID() echoes its value, you can't use it in that context. Change it to get_the_ID(). Many functions in WordPress follow this pattern- one function will print, while the same function with get_ prepended will return its value.


0

Check if the query object is_main_query to target only the main archive query and exclude additional queries. add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if($query->is_main_query() && ( is_category() || is_tag() )) { $query->set( 'post_type', array('post','cpt') ); } }


0

It is sometimes irritating that some build-in functions don't have appropriate filters to modify their output. get_boundary_post() is one of those build-in functions. Unfortunately it does not get posts according to post type, only taxonomy. You can still however make use of this function to get the first and last post. It does support the $in_same_term ...


0

You can get the Packages of the current Proposal using wp_get_object_terms() and then pass some/all of those into a WP_Query. $terms = wp_get_object_terms( $post_id, 'packages', array( 'fields' => 'ids' ) ); $args = array( 'post_type' => 'proposals', 'tax_query' => array( array( 'taxonomy' => 'packages', ...


0

A bit late but, just in case someone needs it on the future. You could add a get_posts inside the normal foreach for users, to check if a given user has stuff published on posts, OR on the CPT you want: if ( ! function_exists( 'contributors_author_list' ) ) : function contributors_author_list() { $contributor_ids = get_users( array( 'fields' ...


1

WordPress has a few of these libraries that come with core, you can view the list here: Default Scripts Included and Registered by WordPress. What you're looking for is Draggable, Sortable, and in your case Droppable. You would use wp_enqueue_script() to add it like so: wp_enqueue_script( 'jquery-ui-droppable' ); WordPress registers these scripts using a ...


1

Instead of event date and event time, make the meta keys start time and end time and save them both as timestamps, then events will order correctly when sorted by start time key only.



Top 50 recent answers are included